Skip to content

Instantly share code, notes, and snippets.

@faiyazalam
Created May 5, 2019 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faiyazalam/b43426089ad84f6d32ecc787b9c1a3f4 to your computer and use it in GitHub Desktop.
Save faiyazalam/b43426089ad84f6d32ecc787b9c1a3f4 to your computer and use it in GitHub Desktop.
Sample implementation of pagination using Zend Paginator and Twig template in Pimcore 5?
//Controller
public function indexAction(Request $request) {
$products = new DataObject\Product\Listing();
$paginator = new \Zend\Paginator\Paginator($products);
$paginator->setCurrentPageNumber($request->get('page'));
$paginator->setItemCountPerPage(20);
return $this->renderTemplate('Controller/index.html.twig', [
'paginator' => $paginator
]);
}
//View
<div class="container">
{% set pages = paginator.getPages() %}
<div class="container">
<div class="row float-left">
<p class="mt-2 ">{{ 'user.footer_total_items'|trans }}
<strong>{{pages.totalItemCount}}</strong>
</p>
</div>
<div class="row justify-content-end">
{% if pages.pageCount > 1 %}
<nav>
<ul class="pagination">
{% if pages.previous is defined %}
{% if pages.previous %}
<li class="page-item"><a class="page-link" href="{{ pimcore_url({ page: pages.previous }) }}">Previous</a></li>
{% endif %}
{% endif %}
{% for page in pages.pagesInRange %}
{% if page == pages.current %}
<li class="active page-item"><span class="page-link">{{ page }}</span></li>
{% else %}
<li class="page-item"><a class="page-link" href="{{ pimcore_url({ page: page }) }}">{{ page }}</a></li>
{% endif %}
{% endfor %}
{% if pages.next is defined %}
{% if pages.next %}
<li class="page-item"><a class="page-link" href="{{ pimcore_url({ page: pages.next }) }}">Next</a></li>
{% endif %}
{% endif %}
</ul>
</nav>
{% endif %}
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment