49 lines
2.3 KiB
Twig
49 lines
2.3 KiB
Twig
{% set _currentPage = app.request.query.get('page') ?: 1 %}
|
|
{% set _currentRoute = app.request.attributes.get('_route') %}
|
|
{% set _lastPage = paginator.lastPage %}
|
|
{% set _currentParams = app.request.query.all|merge(app.request.attributes.get('_route_params')) %}
|
|
|
|
{% if paginator.lastPage > 1 %}
|
|
<nav>
|
|
<ul class="pagination justify-content-center">
|
|
<li class="page-item{{ _currentPage <= 1 ? ' disabled' : '' }}">
|
|
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: _currentPage - 1})) }}" aria-label="Previous">
|
|
« {{ "Previous"|trans }}
|
|
</a>
|
|
</li>
|
|
{% set startPage = max(1, _currentPage - 2) %}
|
|
{% set endPage = min(_lastPage, startPage + 4) %}
|
|
{% if startPage > 1 %}
|
|
<li class="page-item">
|
|
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: 1})) }}">1</a>
|
|
</li>
|
|
{% if startPage > 2 %}
|
|
<li class="page-item disabled">
|
|
<span class="page-link">...</span>
|
|
</li>
|
|
{% endif %}
|
|
{% endif %}
|
|
{% for i in startPage..endPage %}
|
|
<li class="page-item {% if i == _currentPage %}active{% endif %}">
|
|
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: i})) }}">{{ i }}</a>
|
|
</li>
|
|
{% endfor %}
|
|
{% if endPage < _lastPage %}
|
|
{% if endPage < _lastPage - 1 %}
|
|
<li class="page-item disabled">
|
|
<span class="page-link">...</span>
|
|
</li>
|
|
{% endif %}
|
|
<li class="page-item">
|
|
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: _lastPage})) }}">{{ _lastPage }}</a>
|
|
</li>
|
|
{% endif %}
|
|
<li class="page-item {{ _currentPage >= paginator.lastPage ? ' disabled' : '' }}">
|
|
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: _currentPage + 1})) }}" aria-label="Next">
|
|
{{ "Next"|trans }} »
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
{% endif %}
|