pager.html.twig

Same filename in this branch
  1. 11.x core/themes/olivero/templates/navigation/pager.html.twig
  2. 11.x core/themes/stable9/templates/navigation/pager.html.twig
  3. 11.x core/themes/starterkit_theme/templates/navigation/pager.html.twig
  4. 11.x core/modules/system/templates/pager.html.twig
Same filename in other branches
  1. 9 core/themes/olivero/templates/navigation/pager.html.twig
  2. 9 core/themes/stable9/templates/navigation/pager.html.twig
  3. 9 core/themes/claro/templates/pager.html.twig
  4. 9 core/themes/stable/templates/navigation/pager.html.twig
  5. 9 core/themes/starterkit_theme/templates/navigation/pager.html.twig
  6. 9 core/themes/classy/templates/navigation/pager.html.twig
  7. 9 core/modules/system/templates/pager.html.twig
  8. 8.9.x core/themes/claro/templates/pager.html.twig
  9. 8.9.x core/themes/stable/templates/navigation/pager.html.twig
  10. 8.9.x core/themes/classy/templates/navigation/pager.html.twig
  11. 8.9.x core/modules/system/templates/pager.html.twig
  12. 10 core/themes/olivero/templates/navigation/pager.html.twig
  13. 10 core/themes/stable9/templates/navigation/pager.html.twig
  14. 10 core/themes/claro/templates/pager.html.twig
  15. 10 core/themes/starterkit_theme/templates/navigation/pager.html.twig
  16. 10 core/modules/system/templates/pager.html.twig

Theme override to display a pager.

Available variables:

  • heading_id: Pagination heading ID.
  • pagination_heading_level: The heading level to use for the pager.
  • items: List of pager items. The list is keyed by the following elements:

    • first: Item for the first page; not present on the first page of results.
    • previous: Item for the previous page; not present on the first page of results.
    • next: Item for the next page; not present on the last page of results.
    • last: Item for the last page; not present on the last page of results.
    • pages: List of pages, keyed by page number.

    Sub-sub elements: items.first, items.previous, items.next, items.last, and each item inside items.pages contain the following elements:

    • href: URL with appropriate query parameters for the item.
    • attributes: A keyed list of HTML attributes for the item.
    • text: The visible text used for the item link, such as "‹ Previous" or "Next ›".
  • current: The page number of the current page.
  • ellipses: If there are more pages than the quantity allows, then an ellipsis before or after the listed pages may be present.

    • previous: Present if the currently visible list of pages does not start at the first page.
    • next: Present if the visible list of pages ends before the last page.

@todo review all uses of the replace() filter below in https://www.drupal.org/node/3053707 as the behavior it addresses will likely change when that issue is completed.

See also

template_preprocess_pager()

1 theme call to pager.html.twig
Pager::getInfo in core/lib/Drupal/Core/Render/Element/Pager.php
Returns the element properties for this element.

File

core/themes/claro/templates/pager.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override to display a pager.
  5. *
  6. * Available variables:
  7. * - heading_id: Pagination heading ID.
  8. * - pagination_heading_level: The heading level to use for the pager.
  9. * - items: List of pager items.
  10. * The list is keyed by the following elements:
  11. * - first: Item for the first page; not present on the first page of results.
  12. * - previous: Item for the previous page; not present on the first page
  13. * of results.
  14. * - next: Item for the next page; not present on the last page of results.
  15. * - last: Item for the last page; not present on the last page of results.
  16. * - pages: List of pages, keyed by page number.
  17. * Sub-sub elements:
  18. * items.first, items.previous, items.next, items.last, and each item inside
  19. * items.pages contain the following elements:
  20. * - href: URL with appropriate query parameters for the item.
  21. * - attributes: A keyed list of HTML attributes for the item.
  22. * - text: The visible text used for the item link, such as "‹ Previous"
  23. * or "Next ›".
  24. * - current: The page number of the current page.
  25. * - ellipses: If there are more pages than the quantity allows, then an
  26. * ellipsis before or after the listed pages may be present.
  27. * - previous: Present if the currently visible list of pages does not start
  28. * at the first page.
  29. * - next: Present if the visible list of pages ends before the last page.
  30. *
  31. * @see template_preprocess_pager()
  32. *
  33. * @todo review all uses of the replace() filter below in
  34. * https://www.drupal.org/node/3053707 as the behavior it addresses will
  35. * likely change when that issue is completed.
  36. */
  37. #}
  38. {% if items %}
  39. <nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
  40. <{{ pagination_heading_level }} id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</{{ pagination_heading_level }}>
  41. <ul class="pager__items js-pager__items">
  42. {# Print first item if we are not on the first page. #}
  43. {% if items.first %}
  44. {% apply spaceless %}
  45. <li class="pager__item pager__item--action pager__item--first">
  46. <a href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title').addClass('pager__link', 'pager__link--action-link') }}>
  47. <span class="visually-hidden">{{ 'First page'|t }}</span>
  48. <span class="pager__item-title pager__item-title--backwards" aria-hidden="true">
  49. {{ items.first.text|default('First'|t)|replace({'«': ''}) }}
  50. </span>
  51. </a>
  52. </li>
  53. {% endapply %}
  54. {% endif %}
  55. {# Print previous item if we are not on the first page. #}
  56. {% if items.previous %}
  57. {% apply spaceless %}
  58. <li class="pager__item pager__item--action pager__item--previous">
  59. <a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel').addClass('pager__link', 'pager__link--action-link') }}>
  60. <span class="visually-hidden">{{ 'Previous page'|t }}</span>
  61. <span class="pager__item-title pager__item-title--backwards" aria-hidden="true">
  62. {{ items.previous.text|default('Previous'|t)|replace({'‹': ''}) }}
  63. </span>
  64. </a>
  65. </li>
  66. {% endapply %}
  67. {% endif %}
  68. {# Add an ellipsis if there are further previous pages. #}
  69. {% if ellipses.previous %}
  70. <li class="pager__item pager__item--ellipsis" role="presentation">&hellip;</li>
  71. {% endif %}
  72. {# Now generate the actual pager piece. #}
  73. {% for key, item in items.pages %}
  74. {% apply spaceless %}
  75. <li class="pager__item{{ current == key ? ' pager__item--active' : '' }} pager__item--number">
  76. {% if current == key %}
  77. {% set title = 'Current page'|t %}
  78. {% else %}
  79. {% set title = 'Go to page @key'|t({'@key': key}) %}
  80. {% endif %}
  81. <a href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title').addClass(['pager__link', current == key ? ' is-active']) }}>
  82. <span class="visually-hidden">
  83. {{ 'Page'|t }}
  84. </span>
  85. {{ key }}
  86. </a>
  87. </li>
  88. {% endapply %}
  89. {% endfor %}
  90. {# Add an ellipsis if there are further next pages. #}
  91. {% if ellipses.next %}
  92. <li class="pager__item pager__item--ellipsis" role="presentation">&hellip;</li>
  93. {% endif %}
  94. {# Print next item if we are not on the last page. #}
  95. {% if items.next %}
  96. {% apply spaceless %}
  97. <li class="pager__item pager__item--action pager__item--next">
  98. <a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel').addClass('pager__link', 'pager__link--action-link') }}>
  99. <span class="visually-hidden">{{ 'Next page'|t }}</span>
  100. <span class="pager__item-title pager__item-title--forward" aria-hidden="true">
  101. {{ items.next.text|default('Next'|t)|replace({'›': ''}) }}
  102. </span>
  103. </a>
  104. </li>
  105. {% endapply %}
  106. {% endif %}
  107. {# Print last item if we are not on the last page. #}
  108. {% if items.last %}
  109. {% apply spaceless %}
  110. <li class="pager__item pager__item--action pager__item--last">
  111. <a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title').addClass('pager__link', 'pager__link--action-link') }}>
  112. <span class="visually-hidden">{{ 'Last page'|t }}</span>
  113. <span class="pager__item-title pager__item-title--forward" aria-hidden="true">
  114. {{ items.last.text|default('Last'|t)|replace({'»': ''}) }}
  115. </span>
  116. </a>
  117. </li>
  118. {% endapply %}
  119. {% endif %}
  120. </ul>
  121. </nav>
  122. {% endif %}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.