src/Storefront/Resources/views/storefront/component/pagination.html.twig line 1

  1. {% block component_pagination_nav %}
  2.     {% set currentPage = ((criteria.offset + 1) / criteria.limit)|round(0, 'ceil') %}
  3.     {% set totalEntities = total ? total : entities.total %}
  4.     {% set totalPages = (totalEntities / criteria.limit)|round(0, 'ceil') %}
  5.     {% set paginationSuffix = '' %}
  6.     {% if paginationLocation %}
  7.         {% set paginationSuffix = '-' ~ paginationLocation %}
  8.     {% endif %}
  9.     {% if totalPages > 1 %}
  10.         <nav aria-label="pagination" class="pagination-nav">
  11.             {% block component_pagination %}
  12.             <ul class="pagination">
  13.                 {% block component_pagination_first %}
  14.                     <li class="page-item page-first{% if currentPage == 1 %} disabled{% endif %}">
  15.                         {% block component_pagination_first_input %}
  16.                             <input type="radio"
  17.                                    {% if currentPage == 1 %}disabled="disabled"{% endif %}
  18.                                    name="p"
  19.                                    id="p-first{{ paginationSuffix }}"
  20.                                    value="1"
  21.                                    class="d-none"
  22.                                    title="pagination">
  23.                         {% endblock %}
  24.                         {% block component_pagination_first_label %}
  25.                             <label class="page-link" for="p-first{{ paginationSuffix }}">
  26.                                 {% block component_pagination_first_link %}
  27.                                     {% sw_icon 'arrow-medium-double-left' style { 'size': 'fluid', 'pack': 'solid'} %}
  28.                                 {% endblock %}
  29.                             </label>
  30.                         {% endblock %}
  31.                     </li>
  32.                 {% endblock %}
  33.                 {% block component_pagination_prev %}
  34.                     <li class="page-item page-prev{% if currentPage == 1 %} disabled{% endif %}">
  35.                         {% block component_pagination_prev_input %}
  36.                             <input type="radio"
  37.                                    {% if currentPage == 1 %}disabled="disabled"{% endif %}
  38.                                    name="p"
  39.                                    id="p-prev{{ paginationSuffix }}"
  40.                                    value="{{ currentPage - 1 }}"
  41.                                    class="d-none"
  42.                                    title="pagination">
  43.                         {% endblock %}
  44.                         {% block component_pagination_prev_label %}
  45.                             <label class="page-link" for="p-prev{{ paginationSuffix }}">
  46.                                 {% block component_pagination_prev_link %}
  47.                                     {% block component_pagination_prev_icon %}
  48.                                         {% sw_icon 'arrow-medium-left' style {'size': 'fluid', 'pack': 'solid'} %}
  49.                                     {% endblock %}
  50.                                 {% endblock %}
  51.                             </label>
  52.                         {% endblock %}
  53.                     </li>
  54.                 {% endblock %}
  55.                 {% block component_pagination_loop %}
  56.                     {% set start = currentPage - 2 %}
  57.                     {% if start <= 0 %}
  58.                         {% set start = currentPage - 1 %}
  59.                         {% if start <= 0 %}
  60.                             {% set start = currentPage %}
  61.                         {% endif %}
  62.                     {% endif %}
  63.                     {% set end = start + 4 %}
  64.                     {% if end > totalPages %}
  65.                         {% set end = totalPages %}
  66.                     {% endif %}
  67.                     {% for page in start..end %}
  68.                         {% set isActive = (currentPage == page) %}
  69.                         {% block component_pagination_item %}
  70.                             <li class="page-item{% if isActive %} active{% endif %}">
  71.                                 {% block component_pagination_item_input %}
  72.                                     <input type="radio"
  73.                                            name="p"
  74.                                            id="p{{ page }}{{ paginationSuffix }}"
  75.                                            value="{{ page }}"
  76.                                            class="d-none"
  77.                                            title="pagination"
  78.                                            {% if isActive %}checked="checked"{% endif %}>
  79.                                 {% endblock %}
  80.                                 {% block component_pagination_item_label %}
  81.                                     <label class="page-link"
  82.                                            for="p{{ page }}{{ paginationSuffix }}">
  83.                                         {% block component_pagination_item_link %}
  84.                                             {% block component_pagination_item_text %}
  85.                                                 {{ page }}
  86.                                             {% endblock %}
  87.                                         {% endblock %}
  88.                                     </label>
  89.                                 {% endblock %}
  90.                             </li>
  91.                         {% endblock %}
  92.                     {% endfor %}
  93.                 {% endblock %}
  94.                 {% block component_pagination_next %}
  95.                     <li class="page-item page-next{% if currentPage == totalPages %} disabled{% endif %}">
  96.                         {% block component_pagination_next_input %}
  97.                             <input type="radio"
  98.                                    {% if currentPage == totalPages %}disabled="disabled"{% endif %}
  99.                                    name="p"
  100.                                    id="p-next{{ paginationSuffix }}"
  101.                                    value="{{ currentPage + 1 }}"
  102.                                    class="d-none"
  103.                                    title="pagination">
  104.                         {% endblock %}
  105.                         {% block component_pagination_next_label %}
  106.                             <label class="page-link" for="p-next{{ paginationSuffix }}">
  107.                                 {% block component_pagination_next_link %}
  108.                                     {% block component_pagination_next_icon %}
  109.                                         {% sw_icon 'arrow-medium-right' style { 'size': 'fluid', 'pack': 'solid'} %}
  110.                                     {% endblock %}
  111.                                 {% endblock %}
  112.                             </label>
  113.                         {% endblock %}
  114.                     </li>
  115.                 {% endblock %}
  116.                 {% block component_pagination_last %}
  117.                     <li class="page-item page-last{% if currentPage == totalPages %} disabled{% endif %}">
  118.                         {% block component_pagination_last_input %}
  119.                             <input type="radio"
  120.                                    {% if currentPage == totalPages %}disabled="disabled"{% endif %}
  121.                                    name="p"
  122.                                    id="p-last{{ paginationSuffix }}"
  123.                                    value="{{ totalPages }}"
  124.                                    class="d-none"
  125.                                    title="pagination">
  126.                         {% endblock %}
  127.                         {% block component_pagination_last_label %}
  128.                             <label class="page-link" for="p-last{{ paginationSuffix }}">
  129.                                 {% block component_pagination_last_link %}
  130.                                     {% block component_pagination_last_icon %}
  131.                                         {% sw_icon 'arrow-medium-double-right' style {
  132.                                             'size': 'fluid',
  133.                                             'pack': 'solid'
  134.                                         } %}
  135.                                     {% endblock %}
  136.                                 {% endblock %}
  137.                             </label>
  138.                         {% endblock %}
  139.                     </li>
  140.                 {% endblock %}
  141.             </ul>
  142.         {% endblock %}
  143.         </nav>
  144.     {% endif %}
  145. {% endblock %}