Created
March 11, 2020 08:25
-
-
Save fyulistian/47b3490c63d6e6e9ebaf00671c17a9b0 to your computer and use it in GitHub Desktop.
Function pagination on twig
This file contains 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
{{ _self.pagination(4, 1, 'http://127.0.0.1:8000/admin/config/system/mutual-funds?page=') }} | |
{% macro pagination(total, current, url, nearbyPagesLimit = 4) %} | |
{% spaceless %} | |
{% if total > 1 %} | |
<ul class="pagination"> | |
{% for i in 1..total %} | |
{% if 0 == (current - nearbyPagesLimit) - loop.index %} | |
<li><a href="{{ (url ~ 1)|e }}">1</a></li> | |
{% if 1 != loop.index %} | |
<li><span>…</span></li> | |
{% endif %} | |
{% elseif 0 == (current + nearbyPagesLimit) - loop.index and (current + nearbyPagesLimit) < total %} | |
<li><span>…</span></li> | |
{% elseif 0 < (current - nearbyPagesLimit) - loop.index %} | |
{% elseif 0 > (current + nearbyPagesLimit) - loop.index %} | |
{% else %} | |
<li {{ current == loop.index ? 'class="active"' }}> | |
{% if current == loop.index %} | |
<span>{{ loop.index }}</span> | |
{% else %} | |
<a href="{{ url ~ loop.index }}">{{ loop.index }}</a> | |
{% endif %} | |
</li> | |
{% endif %} | |
{% endfor %} | |
{% if current != total and (current + nearbyPagesLimit) < total %} | |
<li><a href="{{ (url ~ total)|e }}">{{ total }}</a></li> | |
{% endif %} | |
</ul> | |
{% endif %} | |
{% endspaceless %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment