Reputation: 1698
I use KnpPaginatorBundle to manage pagination in the backoffice of my site and it works well
I configured it to use a custom templates
knp_paginator:
template:
pagination: MyappMainBundle::pagination.html.twig
Then, I want to use the same bundle in the frontoffice but with different html structure. So, my question is : Is it possible to have two templates for the pagination? One for the backoffice and One for the frontoffice.
Thanks in advance for your answer.
Upvotes: 2
Views: 5894
Reputation: 39390
You can customise the pagination template in the controller:
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate($target, $page);
$pagination->setTemplate('MyBundle:Pagination:pagination.html.twig');
$pagination->setSortableTemplate('MyBundle:Pagination:sortable.html.twig');
In the View:
{% do pagination.setTemplate('MyBundle:Pagination:pagination.html.twig') %}
or (better) in the render method:
{{ knp_pagination_render(pagination, 'MyBundle:Pagination:pagination.html.twig') }}
More info in the doc of the bundle
Upvotes: 7