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) %}
  13.     {%- set alreadyOutput = false -%}
  14.     {%- if page_number == 1 -%}
  15.         {%- set _route = route -%}
  16.         {%- if 'profile_list.list_by_city' in _route -%}
  17.             {%- set _query = query|merge({(pageParameterName): '1'}) -%}
  18.             {% set linkToProfileList = path('profile_list.list_by_city._pagination', _query)|replace({'/page1': ''}) %}
  19.             {{- linkToProfileList|lower -}}
  20.             {%- set alreadyOutput = true -%}
  21.         {%- endif -%}
  22.         {%- set _query = query|filter((v, k) => k != pageParameterName) -%}
  23.     {%- else -%}
  24.         {%- set _route = route~'._pagination' -%}
  25.         {%- set _query = query|merge({(pageParameterName): page_number}) -%}
  26.     {%- endif -%}
  27.     
  28.     {%- if not alreadyOutput -%}
  29.         {{- path(_route, _query)|lower -}}
  30.     {%- endif -%}
  31. {% endmacro %}
  32. {% from _self import _pagination_path %}
  33. <div class="mb-4" id="pagination_container">
  34. {% if pageCount > 1 %}
  35.     <nav class="pagination-content d-flex" id="pagination-content">
  36.         {% set classAlign = (align is not defined) ? '' : align=='center' ? ' justify-content-center' : (align=='right' ? ' justify-content-end' : '') %}
  37.         {% set classSize = (size is not defined) ? '' : size=='large' ? ' pagination-lg' : (size=='small' ? ' pagination-sm' : '') %}
  38.         <ul class="pagination{{ classAlign }}{{ classSize }} d-flex-c">
  39.             <li class="pagination-item pagination-item--prev d-flex-c">
  40.                 {% if previous is defined %}
  41.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, 1) }}">
  42.                 {% else %}
  43.                 <span class="pagination-link d-flex-c disable">
  44.                 {% endif %}
  45.                     <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>
  46.                 {% if previous is defined %}
  47.                 </a>
  48.                 {% else %}
  49.                 </span>
  50.                 {% endif %}
  51.             </li>
  52.             {# Previous #}
  53.             <li class="pagination-item pagination-item--prev d-flex-c">
  54.                 {% if previous is defined %}
  55.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, previous) }}">
  56.                 {% else %}
  57.                 <span class="pagination-link d-flex-c disable">
  58.                 {% endif %}
  59.                     <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>
  60.                 {% if previous is defined %}
  61.                 </a>
  62.                 {% else %}
  63.                 </span>
  64.                 {% endif %}
  65.             </li>
  66.             {% if startPage > 1 %}
  67.                 <li class="pagination-item d-flex-c">
  68.                     <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, 1) }}">1</a>
  69.                 </li>
  70.                 {% if startPage == 3 %}
  71.                     <li class="pagination-item d-flex-c">
  72.                         <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, 2) }}">2</a>
  73.                     </li>
  74.                 {% elseif startPage != 2 %}
  75.                     <li class="pagination-item d-flex-c disabled">
  76.                         <span class="pagination-link d-flex-c">&hellip;</span>
  77.                     </li>
  78.                 {% endif %}
  79.             {% endif %}
  80.             {% for page in pagesInRange %}
  81.                 {% if page != current %}
  82.                     <li class="pagination-item d-flex-c">
  83.                         <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, page) }}">{{ page }}</a>
  84.                     </li>
  85.                 {% else %}
  86.                     <li class="pagination-item d-flex-c active">
  87.                         <span class="pagination-link d-flex-c">{{ page }}</span>
  88.                     </li>
  89.                 {% endif %}
  90.             {% endfor %}
  91.             {% if pageCount > endPage %}
  92.                 {% if pageCount > (endPage + 1) %}
  93.                     {% if pageCount > (endPage + 2) %}
  94.                         <li class="pagination-item d-flex-c disabled">
  95.                             <span class="pagination-link d-flex-c">&hellip;</span>
  96.                         </li>
  97.                     {% else %}
  98.                         <li class="pagination-item d-flex-c">
  99.                             <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, (pageCount - 1)) }}">{{ pageCount -1 }}</a>
  100.                         </li>
  101.                     {% endif %}
  102.                 {% endif %}
  103.                 <li class="pagination-item d-flex-c">
  104.                     <a class="pagination-link d-flex-c" href="{{ _pagination_path(route, query, pageParameterName, pageCount) }}">{{ pageCount }}</a>
  105.                 </li>
  106.             {% endif %}
  107.             {# Next #}
  108.             <li class="pagination-item pagination-item--next d-flex-c" data-t="{{startPage}}">
  109.                 {% if next is defined %}
  110.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, next) }}">
  111.                 {% else %}
  112.                 <span class="pagination-link d-flex-c disable">
  113.                 {% endif %}
  114.                     <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>
  115.                 {% if next is defined %}
  116.                 </a>
  117.                 {% else %}
  118.                 </span>
  119.                 {% endif %}
  120.             </li>
  121.             {# Double next #}
  122.             <li class="pagination-item pagination-item--next d-flex-c">
  123.                 {% if next is defined %}
  124.                 <a class="pagination-link d-flex-c" rel="prev" href="{{ _pagination_path(route, query, pageParameterName, pageCount) }}">
  125.                 {% else %}
  126.                 <span class="pagination-link d-flex-c disable">
  127.                 {% endif %}
  128.                     <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>
  129.                 {% if next is defined %}
  130.                 </a>
  131.                 {% else %}
  132.                 </span>
  133.                 {% endif %}
  134.             </li>
  135.         </ul>
  136.     </nav>
  137. {% endif %}
  138. </div>
  139. <script>
  140. (function(){
  141.     const showmore = document.getElementById('showmore_container');
  142.     if (!showmore) return;
  143.     if (showmore.hasAttribute('data-fix-with')) return;
  144.     const pagination = document.querySelector('#pagination-content .pagination');
  145.     showmore.style.setProperty('--btn-width', `${pagination.offsetWidth < 130 ? 130 : (pagination.offsetWidth - 20)}px`);
  146. })();
  147. </script>