2021-02-21 16:37:27 +00:00
|
|
|
{% macro pagination(total, current, url, nearbyPagesLimit = 4) %}
|
|
|
|
|
|
|
|
{# Create "main_url" variable with link for the first page #}
|
|
|
|
{% set foo = url|split('/') %}
|
|
|
|
{% set foo = foo|slice(0, -1) %}
|
|
|
|
{% set main_url = foo|join('/') ~ "/" %}
|
|
|
|
|
|
|
|
{% apply spaceless %}
|
|
|
|
{% if total > 1 %}
|
|
|
|
<div class="row">
|
|
|
|
<nav>
|
|
|
|
<ul class="pagination">
|
|
|
|
{% if current > 1 %}
|
|
|
|
<li class="pagination__item pagination__item_arrow">
|
|
|
|
<a class="prev pagination__link pagination__link_arrow pagination__link_arrow_prev" href="{{ (url ~ (current-1))|e }}">«</a>
|
|
|
|
</li>
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% for i in 1..total %}
|
|
|
|
{% if 0 == (current - nearbyPagesLimit) - loop.index %}
|
|
|
|
<li class="pagination__item">
|
|
|
|
<a href="{{ (url ~ 1)|e }}" class="pagination__link">1
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
{% if 1 != loop.index %}
|
|
|
|
<li class="pagination__item">
|
2021-07-15 22:37:33 +00:00
|
|
|
<div class="pagination__link"><span>...</span></div>
|
2021-02-21 16:37:27 +00:00
|
|
|
</li>
|
|
|
|
{% endif %}
|
|
|
|
{% elseif 0 == (current + nearbyPagesLimit) - loop.index and (current + nearbyPagesLimit) < total %}
|
2021-07-15 22:37:33 +00:00
|
|
|
<li class="pagination__item pagination__item_see-more"><div class="pagination__link_see-more pagination__link"><span>...</span></div></li>
|
2021-02-21 16:37:27 +00:00
|
|
|
{% elseif 0 < (current - nearbyPagesLimit) - loop.index %}
|
|
|
|
{% elseif 0 > (current + nearbyPagesLimit) - loop.index %}
|
|
|
|
{% else %}
|
2021-07-15 22:37:33 +00:00
|
|
|
{% if current == loop.index %}
|
|
|
|
<li class="active pagination__item pagination__item_active"><div class="pagination__link"><span aria-current="page">{{ loop.index }}</span></div></li>
|
2021-02-21 16:37:27 +00:00
|
|
|
{% else %}
|
|
|
|
{% if loop.index == 1 %}
|
|
|
|
<li class="pagination__item"><a href="{{ main_url }}" class="pagination__link">{{ loop.index }}</a></li>
|
|
|
|
{% else %}
|
|
|
|
<li class="pagination__item"><a href="{{ url ~ loop.index }}" class="pagination__link">{{ loop.index }}</a></li>
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
{% if current != total and (current + nearbyPagesLimit) < total %}
|
|
|
|
<li class="pagination__item"><a href="{{ (url ~ total)|e }}" class="pagination__link">{{ total }}</a></li>
|
|
|
|
{% endif %}
|
|
|
|
{% if current < total %}
|
|
|
|
<li class="pagination__item pagination__item_arrow"><a class="next pagination__link pagination__link_arrow pagination__link_arrow_next" href="{{ (url ~ (current+1))|e }}">»</a></li>
|
|
|
|
{% endif %}
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
|
|
|
{% endapply %}
|
|
|
|
{% endmacro %}
|
|
|
|
|
|
|
|
{{ _self.pagination(total, current, url) }}
|