This code is from the symfony Knp-paginator-bundle and lives in a Twig Extension class (PaginationExtension.php
). I'm wondering (just curiosity) where the second argument: SlidingPagination $pagination
in the render() method comes from, since this argument is not supplied in twig. Anyone an idea?
/**
* {@inheritDoc}
*/
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('knp_pagination_render', array($this, 'render'), array('is_safe' => array('html'), 'needs_environment' => true))
);
}
/**
* Renders the pagination template
*/
public function render(\Twig_Environment $env, SlidingPagination $pagination, $template = null, array $queryParams = array(), array $viewParams = array())
{
return $env->render(
$template ?: $pagination->getTemplate(),
$this->processor->render($pagination, $queryParams, $viewParams)
);
}
In Twig the extension is used like this:
{{ knp_pagination_render(projects) }}
Actually SlidingPagination $pagination
comes from projects
in twig call: {{ knp_pagination_render(projects) }}
\Twig_Environment $env
is inserted to all extension functions by twig.