-
-
Save barchard/9942534 to your computer and use it in GitHub Desktop.
Updated for Bootstrap v3. Fixing issue with Next/Previous not using arrows. Fixing issue where in (in previous Bootstrap comment) arrows were not disabled if "showAlways" was true.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
Source: http://dev.dbl-a.com/symfony-2-0/symfony2-and-twig-pagination/ | |
Updated by: Simon Schick <[email protected]> | |
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 | |
#} | |
{% spaceless %} | |
{% if lastPage > 1 %} | |
{# the number of first and last pages to be displayed #} | |
{% set extremePagesLimit = 3 %} | |
{# the number of pages that are displayed around the active page #} | |
{% set nearbyPagesLimit = 2 %} | |
<div class="row"> | |
<ul class="pagination"> | |
{% if currentPage > 1 %} | |
<li><a href="{{ paginationPath }}{{ currentPage-1 }}">«</a></li> | |
{% for i in range(1, extremePagesLimit) if ( i < currentPage - nearbyPagesLimit ) %} | |
<li><a href="{{ paginationPath }}{{ i }}">{{ i }}</a></li> | |
{% endfor %} | |
{% if extremePagesLimit + 1 < currentPage - nearbyPagesLimit %} | |
<li class="disabled"><a>...</a></li> | |
{% endif %} | |
{% for i in range(currentPage-nearbyPagesLimit, currentPage-1) if ( i > 0 ) %} | |
<li><a href="{{ paginationPath }}{{ i }}">{{ i }}</a></li> | |
{% endfor %} | |
{% elseif showAlwaysFirstAndLast %} | |
<li class="disabled"><a>«</a></li> | |
{% endif %} | |
<li class="active"><a>{{ currentPage }}</a></li> | |
{% if currentPage < lastPage %} | |
{% for i in range(currentPage+1, currentPage + nearbyPagesLimit) if ( i <= lastPage ) %} | |
<li><a href="{{ paginationPath }}{{ i }}">{{ i }}</a></li> | |
{% endfor %} | |
{% if (lastPage - extremePagesLimit) > (currentPage + nearbyPagesLimit) %} | |
<li class="disabled"><a>...</a></li> | |
{% endif %} | |
{% for i in range(lastPage - extremePagesLimit+1, lastPage) if ( i > currentPage + nearbyPagesLimit ) %} | |
<li><a href="{{ paginationPath }}{{ i }}">{{ i }}</a></li> | |
{% endfor %} | |
<li><a href="{{ paginationPath }}{{ currentPage+1 }}">»</a></li> | |
{% elseif showAlwaysFirstAndLast %} | |
<li class="disabled"><a>»</a></li> | |
{% endif %} | |
</ul> | |
</div> | |
{% endif %} | |
{% endspaceless %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.