Guest User

Untitled

a guest
Jan 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. {% spaceless %}
  2. {% if lastPage > 1 %}
  3.  
  4. {# the number of first and last pages to be displayed #}
  5. {% set extremePagesLimit = 3 %}
  6.  
  7. {# the number of pages that are displayed around the active page #}
  8. {% set nearbyPagesLimit = 2 %}
  9.  
  10. {% if currentFilters is not defined %}{% set currentFilters = {} %}{% endif %}
  11. {% if paginationPath is not defined %}{% set paginationPath = app.request.attributes.get('_route') %}{% endif %}
  12. {% if showAlwaysFirstAndLast is not defined %}{% set showAlwaysFirstAndLast = true %}{% endif %}
  13.  
  14. <nav aria-label="Page navigation example">
  15. <ul class="pagination">
  16. {% if currentPage > 1 %}
  17. <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: currentPage-1})) }}">Previous</a></li>
  18.  
  19. {% for i in range(1, extremePagesLimit) if ( i < currentPage - nearbyPagesLimit ) %}
  20. <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
  21. {% endfor %}
  22.  
  23. {% if extremePagesLimit + 1 < currentPage - nearbyPagesLimit %}
  24. <li class="page-item"><span class="sep-dots">...</span></li>
  25. {% endif %}
  26.  
  27. {% for i in range(currentPage-nearbyPagesLimit, currentPage-1) if ( i > 0 ) %}
  28. <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
  29. {% endfor %}
  30. {% elseif showAlwaysFirstAndLast %}
  31. <li class="page-item disabled"><a class="page-link" href="#">Previous</a></li>
  32. {% endif %}
  33.  
  34. <li class="page-item active"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({ page: currentPage })) }}">{{ currentPage }}</a></li>
  35.  
  36. {% if currentPage < lastPage %}
  37. {% for i in range(currentPage+1, currentPage + nearbyPagesLimit) if ( i <= lastPage ) %}
  38. <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
  39. {% endfor %}
  40.  
  41. {% if (lastPage - extremePagesLimit) > (currentPage + nearbyPagesLimit) %}
  42. <li class="page-item"><span class="sep-dots">...</span></li>
  43. {% endif %}
  44.  
  45. {% for i in range(lastPage - extremePagesLimit+1, lastPage) if ( i > currentPage + nearbyPagesLimit ) %}
  46. <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: i})) }}">{{ i }}</a></li>
  47. {% endfor %}
  48.  
  49. <li class="page-item"><a class="page-link" href="{{ path(paginationPath, currentFilters|merge({page: currentPage+1})) }}">Next</a></li>
  50. {% elseif showAlwaysFirstAndLast %}
  51. <li class="page-item disabled"><a class="page-link" href="#">Next</a></li>
  52. {% endif %}
  53. </ul>
  54. </nav>
  55. {% endif %}
  56. {% endspaceless %}
Add Comment
Please, Sign In to add comment