pager.html.twig 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a pager.
  5. *
  6. * Available variables:
  7. * - heading_id: Pagination heading ID.
  8. * - items: List of pager items.
  9. * The list is keyed by the following elements:
  10. * - first: Item for the first page; not present on the first page of results.
  11. * - previous: Item for the previous page; not present on the first page
  12. * of results.
  13. * - next: Item for the next page; not present on the last page of results.
  14. * - last: Item for the last page; not present on the last page of results.
  15. * - pages: List of pages, keyed by page number.
  16. * Sub-sub elements:
  17. * items.first, items.previous, items.next, items.last, and each item inside
  18. * items.pages contain the following elements:
  19. * - href: URL with appropriate query parameters for the item.
  20. * - attributes: A keyed list of HTML attributes for the item.
  21. * - text: The visible text used for the item link, such as "‹ Previous"
  22. * or "Next ›".
  23. * - current: The page number of the current page.
  24. * - ellipses: If there are more pages than the quantity allows, then an
  25. * ellipsis before or after the listed pages may be present.
  26. * - previous: Present if the currently visible list of pages does not start
  27. * at the first page.
  28. * - next: Present if the visible list of pages ends before the last page.
  29. *
  30. * @see template_preprocess_pager()
  31. *
  32. * @ingroup themeable
  33. */
  34. #}
  35. {% if items %}
  36. <nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
  37. <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
  38. <ul class="pager__items js-pager__items">
  39. {# Print first item if we are not on the first page. #}
  40. {% if items.first %}
  41. <li class="pager__item pager__item--first">
  42. <a href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title') }}>
  43. <span class="visually-hidden">{{ 'First page'|t }}</span>
  44. <span aria-hidden="true">{{ items.first.text|default('« First'|t) }}</span>
  45. </a>
  46. </li>
  47. {% endif %}
  48. {# Print previous item if we are not on the first page. #}
  49. {% if items.previous %}
  50. <li class="pager__item pager__item--previous">
  51. <a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel') }}>
  52. <span class="visually-hidden">{{ 'Previous page'|t }}</span>
  53. <span aria-hidden="true">{{ items.previous.text|default('‹ Previous'|t) }}</span>
  54. </a>
  55. </li>
  56. {% endif %}
  57. {# Add an ellipsis if there are further previous pages. #}
  58. {% if ellipses.previous %}
  59. <li class="pager__item pager__item--ellipsis" role="presentation">&hellip;</li>
  60. {% endif %}
  61. {# Now generate the actual pager piece. #}
  62. {% for key, item in items.pages %}
  63. <li class="pager__item{{ current == key ? ' is-active' : '' }}">
  64. {% if current == key %}
  65. {% set title = 'Current page'|t %}
  66. {% else %}
  67. {% set title = 'Go to page @key'|t({'@key': key}) %}
  68. {% endif %}
  69. <a href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title') }}>
  70. <span class="visually-hidden">
  71. {{ current == key ? 'Current page'|t : 'Page'|t }}
  72. </span>
  73. {{- key -}}
  74. </a>
  75. </li>
  76. {% endfor %}
  77. {# Add an ellipsis if there are further next pages. #}
  78. {% if ellipses.next %}
  79. <li class="pager__item pager__item--ellipsis" role="presentation">&hellip;</li>
  80. {% endif %}
  81. {# Print next item if we are not on the last page. #}
  82. {% if items.next %}
  83. <li class="pager__item pager__item--next">
  84. <a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel') }}>
  85. <span class="visually-hidden">{{ 'Next page'|t }}</span>
  86. <span aria-hidden="true">{{ items.next.text|default('Next ›'|t) }}</span>
  87. </a>
  88. </li>
  89. {% endif %}
  90. {# Print last item if we are not on the last page. #}
  91. {% if items.last %}
  92. <li class="pager__item pager__item--last">
  93. <a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title') }}>
  94. <span class="visually-hidden">{{ 'Last page'|t }}</span>
  95. <span aria-hidden="true">{{ items.last.text|default('Last »'|t) }}</span>
  96. </a>
  97. </li>
  98. {% endif %}
  99. </ul>
  100. </nav>
  101. {% endif %}