templates/_pagination.html.twig line 1

Open in your IDE?
  1. {#
  2. /**
  3.  * @file
  4.  * Twitter Bootstrap v4-beta.2 Sliding pagination control implementation.
  5.  *
  6.  * View that can be used with the pagination module
  7.  * from the Twitter Bootstrap CSS Toolkit
  8.  * https://getbootstrap.com/docs/4.0/components/pagination/
  9.  *
  10.  */
  11. #}
  12. {% macro _pagination_path(route, query, pageParameterName, page_number) %}{% if page_number == 1 %}{% set _route = route %}{% set _query = query|filter((v, k) => k != pageParameterName) %}{% else %}{% set _route = route~'._pagination' %}{% set _query = query|merge({(pageParameterName): page_number}) %}{% endif %}{{ path(_route, _query)|lower }}{% endmacro %}
  13. {% from _self import _pagination_path %}
  14. <div class="mb-4" id="pagination_container">
  15. {% if pageCount > 1 %}
  16.     <nav class="pagination-content d-flex" id="pagination-content">
  17.         {% set classAlign = (align is not defined) ? '' : align=='center' ? ' justify-content-center' : (align=='right' ? ' justify-content-end' : '') %}
  18.         {% set classSize = (size is not defined) ? '' : size=='large' ? ' pagination-lg' : (size=='small' ? ' pagination-sm' : '') %}
  19.         <ul class="pagination{{ classAlign }}{{ classSize }} d-flex-c">
  20.             <li class="pagination-item pagination-item--prev d-flex-c">
  21.                 {% if previous is defined %}
  22.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, 1) }}">
  23.                 {% else %}
  24.                 <span class="pagination-link d-flex-c disable">
  25.                 {% endif %}
  26.                     <svg width="24" height="25" fill="none"><path d="m18.705 17.208-4.58-4.59 4.58-4.59-1.41-1.41-6 6 6 6 1.41-1.41Z"/><path d="m12.705 17.208-4.58-4.59 4.58-4.59-1.41-1.41-6 6 6 6 1.41-1.41Z"/></svg>
  27.                 {% if previous is defined %}
  28.                 </a>
  29.                 {% else %}
  30.                 </span>
  31.                 {% endif %}
  32.             </li>
  33.             {# Previous #}
  34.             <li class="pagination-item pagination-item--prev d-flex-c">
  35.                 {% if previous is defined %}
  36.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, previous) }}">
  37.                 {% else %}
  38.                 <span class="pagination-link d-flex-c disable">
  39.                 {% endif %}
  40.                     <svg width="24" height="25" fill="none"><path d="m15.705 17.208-4.58-4.59 4.58-4.59-1.41-1.41-6 6 6 6 1.41-1.41Z"/></svg>
  41.                 {% if previous is defined %}
  42.                 </a>
  43.                 {% else %}
  44.                 </span>
  45.                 {% endif %}
  46.             </li>
  47.             {% if startPage > 1 %}
  48.                 <li class="pagination-item d-flex-c">
  49.                     <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, 1) }}">1</a>
  50.                 </li>
  51.                 {% if startPage == 3 %}
  52.                     <li class="pagination-item d-flex-c">
  53.                         <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, 2) }}">2</a>
  54.                     </li>
  55.                 {% elseif startPage != 2 %}
  56.                     <li class="pagination-item d-flex-c disabled">
  57.                         <span class="pagination-link d-flex-c">&hellip;</span>
  58.                     </li>
  59.                 {% endif %}
  60.             {% endif %}
  61.             {% for page in pagesInRange %}
  62.                 {% if page != current %}
  63.                     <li class="pagination-item d-flex-c">
  64.                         <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, page) }}">{{ page }}</a>
  65.                     </li>
  66.                 {% else %}
  67.                     <li class="pagination-item d-flex-c active">
  68.                         <span class="pagination-link d-flex-c">{{ page }}</span>
  69.                     </li>
  70.                 {% endif %}
  71.             {% endfor %}
  72.             {% if pageCount > endPage %}
  73.                 {% if pageCount > (endPage + 1) %}
  74.                     {% if pageCount > (endPage + 2) %}
  75.                         <li class="pagination-item d-flex-c disabled">
  76.                             <span class="pagination-link d-flex-c">&hellip;</span>
  77.                         </li>
  78.                     {% else %}
  79.                         <li class="pagination-item d-flex-c">
  80.                             <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, (pageCount - 1)) }}">{{ pageCount -1 }}</a>
  81.                         </li>
  82.                     {% endif %}
  83.                 {% endif %}
  84.                 <li class="pagination-item d-flex-c">
  85.                     <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, pageCount) }}">{{ pageCount }}</a>
  86.                 </li>
  87.             {% endif %}
  88.             {# Next #}
  89.             <li class="pagination-item pagination-item--next d-flex-c" data-t="{{startPage}}">
  90.                 {% if next is defined %}
  91.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, next) }}">
  92.                 {% else %}
  93.                 <span class="pagination-link d-flex-c disable">
  94.                 {% endif %}
  95.                     <svg width="24" height="25" fill="none"><path d="m8.295 17.208 4.58-4.59-4.58-4.59 1.41-1.41 6 6-6 6-1.41-1.41Z"/></svg>
  96.                 {% if next is defined %}
  97.                 </a>
  98.                 {% else %}
  99.                 </span>
  100.                 {% endif %}
  101.             </li>
  102.             {# Double next #}
  103.             <li class="pagination-item pagination-item--next d-flex-c">
  104.                 {% if next is defined %}
  105.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, pageCount) }}">
  106.                 {% else %}
  107.                 <span class="pagination-link d-flex-c disable">
  108.                 {% endif %}
  109.                     <svg width="24" height="25" fill="none"><path d="m5.295 17.208 4.58-4.59-4.58-4.59 1.41-1.41 6 6-6 6-1.41-1.41Z"/><path d="m11.295 17.208 4.58-4.59-4.58-4.59 1.41-1.41 6 6-6 6-1.41-1.41Z"/></svg>
  110.                 {% if next is defined %}
  111.                 </a>
  112.                 {% else %}
  113.                 </span>
  114.                 {% endif %}
  115.             </li>
  116.         </ul>
  117.     </nav>
  118. {% endif %}
  119. </div>
  120. <script>
  121. (function(){
  122.     const showmore = document.getElementById('showmore_container');
  123.     if (!showmore) return;
  124.     if (showmore.hasAttribute('data-fix-with')) return;
  125.     const pagination = document.querySelector('#pagination-content .pagination');
  126.     showmore.style.setProperty('--btn-width', `${pagination.offsetWidth < 130 ? 130 : (pagination.offsetWidth - 20)}px`);
  127. })();
  128. </script>