templates/blog/_pagination.html.twig line 1

Open in your IDE?
  1. {% if totalPages > 1 %}
  2.     <nav aria-label="Blog pagination">
  3.         <ul class="pagination justify-content-center">
  4.             {# Previous page link #}
  5.             {% if currentPage > 1 %}
  6.                 <li class="page-item">
  7.                     <a class="page-link" href="{{ path(route, routeParams|merge({'page': currentPage - 1})) }}" aria-label="Previous">
  8.                         <span aria-hidden="true">&laquo;</span>
  9.                     </a>
  10.                 </li>
  11.             {% else %}
  12.                 <li class="page-item disabled">
  13.                     <span class="page-link" aria-hidden="true">&laquo;</span>
  14.                 </li>
  15.             {% endif %}
  16.             
  17.             {# Page number links #}
  18.             {% set startPage = max(1, currentPage - 2) %}
  19.             {% set endPage = min(totalPages, startPage + 4) %}
  20.             {% if endPage - startPage < 4 %}
  21.                 {% set startPage = max(1, endPage - 4) %}
  22.             {% endif %}
  23.             
  24.             {% for i in startPage..endPage %}
  25.                 <li class="page-item {% if i == currentPage %}active{% endif %}">
  26.                     {% if i == currentPage %}
  27.                         <span class="page-link">{{ i }}</span>
  28.                     {% else %}
  29.                         <a class="page-link" href="{{ path(route, routeParams|merge({'page': i})) }}">{{ i }}</a>
  30.                     {% endif %}
  31.                 </li>
  32.             {% endfor %}
  33.             
  34.             {# Next page link #}
  35.             {% if currentPage < totalPages %}
  36.                 <li class="page-item">
  37.                     <a class="page-link" href="{{ path(route, routeParams|merge({'page': currentPage + 1})) }}" aria-label="Next">
  38.                         <span aria-hidden="true">&raquo;</span>
  39.                     </a>
  40.                 </li>
  41.             {% else %}
  42.                 <li class="page-item disabled">
  43.                     <span class="page-link" aria-hidden="true">&raquo;</span>
  44.                 </li>
  45.             {% endif %}
  46.         </ul>
  47.     </nav>
  48. {% endif %}