Created
October 3, 2013 15:52
-
-
Save blackreaven/6812134 to your computer and use it in GitHub Desktop.
Twig pager
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
{# | |
# count => total item | |
# limit => item by page | |
# offset => start item idex | |
# page => current page | |
# lastpage => last page = page number | |
# adjacents => page count display before and after the current page | |
#} | |
{% if limit is not defined %} | |
{% set limit = 10 %} | |
{% endif %} | |
{% if offset is not defined %} | |
{% set offset = 0 %} | |
{% endif %} | |
{% if adjacents is not defined %} | |
{% set adjacents = 2 %} | |
{% endif %} | |
{% set lastpage = count//limit+1 %} | |
{% set page = offset//limit+1 %} | |
{% if lastpage > 1 %} | |
<ul class="list-pagination"> | |
{# previous page #} | |
{% if page > 1 %} | |
<li class="prev"> | |
<a class="link-arrow left" href="#"> | |
<span class="desktop-only">Précédent</span> | |
<span class="tablet-only"> | |
<abbr title="Précédent">Préc.</abbr> | |
</span> | |
</a> | |
</li> | |
{% endif %} | |
{# pages #} | |
{% if lastpage <= 7 + (adjacents * 2) %} | |
{% for i in range(1,lastpage) %} | |
{% if i == page %} | |
<li class="active"><a href="#">{{ i }}</a></li> | |
{% else %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% else %} | |
{% if page < 1 + (adjacents * 3) %} | |
{% for i in range(1,1 + (adjacents * 2)) %} | |
{% if i == page %} | |
<li class="active"><a href="#">{{ i }}</a></li> | |
{% else %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endif %} | |
{% endfor %} | |
<li class="">...</li> | |
{% for i in range(lastpage - adjacents,lastpage) %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endfor %} | |
{% elseif lastpage - ( adjacents * 2 ) > page and page > adjacents * 2 %} | |
{% for i in range(1,adjacents) %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endfor %} | |
<li class="">...</li> | |
{% for i in range(page-adjacents,page + adjacents) %} | |
{% if i == page %} | |
<li class="active"><a href="#">{{ i }}</a></li> | |
{% else %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endif %} | |
{% endfor %} | |
<li class="">...</li> | |
{% for i in range(lastpage + 1 - adjacents,lastpage) %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endfor %} | |
{% else %} | |
{% for i in range(1,adjacents) %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endfor %} | |
<li class="">... | |
<li> | |
{% for i in range(lastpage - 1 -adjacents , lastpage) %} | |
{% if i == page %} | |
<li class="active"><a href="#">{{ i }}</a></li> | |
{% else %} | |
<li class=""><a href="#">{{ i }}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% endif %} | |
{% endif %} | |
{# next page #} | |
{% if page < lastpage - 1 %} | |
<li class="next"> | |
<a class="link-arrow right" href="#"> | |
<span class="desktop-only">Suivant</span> | |
<span class="tablet-only"><abbr title="Suivant">Suiv.</abbr></span> | |
</a> | |
</li> | |
{% endif %} | |
</ul> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment