Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {% 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 %}
- {% if currentFilters is not defined %}{% set currentFilters = {} %}{% endif %}
- {% if paginationPath is not defined %}{% set paginationPath = app.request.attributes.get('_route') %}{% endif %}
- {% if showAlwaysFirstAndLast is not defined %}{% set showAlwaysFirstAndLast = true %}{% endif %}
- <nav aria-label="Page navigation example">
- <ul class="pagination">
- {% if currentPage > 1 %}
- <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: currentPage-1})) }}">Previous</a></li>
- {% for i in range(1, extremePagesLimit) if ( i < currentPage - nearbyPagesLimit ) %}
- <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
- {% endfor %}
- {% if extremePagesLimit + 1 < currentPage - nearbyPagesLimit %}
- <li class="page-item"><span class="sep-dots">...</span></li>
- {% endif %}
- {% for i in range(currentPage-nearbyPagesLimit, currentPage-1) if ( i > 0 ) %}
- <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
- {% endfor %}
- {% elseif showAlwaysFirstAndLast %}
- <li class="page-item disabled"><a class="page-link" href="#">Previous</a></li>
- {% endif %}
- <li class="page-item active"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({ page: currentPage })) }}">{{ currentPage }}</a></li>
- {% if currentPage < lastPage %}
- {% for i in range(currentPage+1, currentPage + nearbyPagesLimit) if ( i <= lastPage ) %}
- <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
- {% endfor %}
- {% if (lastPage - extremePagesLimit) > (currentPage + nearbyPagesLimit) %}
- <li class="page-item"><span class="sep-dots">...</span></li>
- {% endif %}
- {% for i in range(lastPage - extremePagesLimit+1, lastPage) if ( i > currentPage + nearbyPagesLimit ) %}
- <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
- {% endfor %}
- <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: currentPage+1})) }}">Next</a></li>
- {% elseif showAlwaysFirstAndLast %}
- <li class="page-item disabled"><a class="page-link" href="#">Next</a></li>
- {% endif %}
- </ul>
- </nav>
- {% endif %}
- {% endspaceless %}
Add Comment
Please, Sign In to add comment