{# Source: http://dev.dbl-a.com/symfony-2-0/symfony2-and-twig-pagination/ Updated by: Simon Schick Parameters: * currentFilters (array) : associative array that contains the current route-arguments * currentPage (int) : the current page you are in * paginationPath (string) : the route name to use for links * showAlwaysFirstAndLast (bool) : Always show first and last link (just disabled) * lastPage (int) : represents the total number of existing pages #} {# Example: {% include 'pagination.html.twig' with { currentFilters: { myFilter: filtervariables }, currentPage: page, paginationPath: "myroute", lastPage: totalPages, showAlwaysFirstAndLast: true } only %} #} {% spaceless %} {% if lastPage > 1 %} {# the number of first and last pages to be displayed #} {% set extremePagesLimit = 2 %} {# the number of pages that are displayed around the active page #} {% set nearbyPagesLimit = 4 %}
    {% if currentPage > 1 %}
  1. {% for i in range(1, extremePagesLimit) if ( i < currentPage - nearbyPagesLimit ) %}
  2. {{ i }}
  3. {% endfor %} {% if extremePagesLimit + 1 < currentPage - nearbyPagesLimit %}
  4. ...
  5. {% endif %} {% for i in range(currentPage-nearbyPagesLimit, currentPage-1) if ( i > 0 ) %}
  6. {{ i }}
  7. {% endfor %} {% elseif showAlwaysFirstAndLast %}
  8. {% endif %}
  9. {{ currentPage }}
  10. {% if currentPage < lastPage %} {% for i in range(currentPage+1, currentPage + nearbyPagesLimit) if ( i <= lastPage ) %}
  11. {{ i }}
  12. {% endfor %} {% if (lastPage - extremePagesLimit) > (currentPage + nearbyPagesLimit) %}
  13. ...
  14. {% endif %} {% for i in range(lastPage - extremePagesLimit+1, lastPage) if ( i > currentPage + nearbyPagesLimit ) %}
  15. {{ i }}
  16. {% endfor %}
  17. {% elseif showAlwaysFirstAndLast %}
  18. {% endif %}
{% endif %} {% endspaceless %}