pager.html.twig

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

Theme override to display a pager.

Available variables:

  • heading_id: Pagination heading ID.
  • 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.

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/olivero/templates/navigation/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. * - 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. #}
  33. {% if items %}
  34. <nav class="pager layout--content-medium" role="navigation" aria-labelledby="{{ heading_id }}">
  35. <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
  36. <ul class="pager__items js-pager__items">
  37. {# Print first item if we are not on the first page. #}
  38. {% if items.first %}
  39. {% apply spaceless %}
  40. <li class="pager__item pager__item--control pager__item--first">
  41. <a href="{{ items.first.href }}" class="pager__link" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title', 'class') }}>
  42. <span class="visually-hidden">{{ 'First page'|t }}</span>
  43. {% include "@olivero/../images/pager-first.svg" %}
  44. </a>
  45. </li>
  46. {% endapply %}
  47. {% endif %}
  48. {# Print previous item if we are not on the first page. #}
  49. {% if items.previous %}
  50. {% apply spaceless %}
  51. <li class="pager__item pager__item--control pager__item--previous">
  52. <a href="{{ items.previous.href }}" class="pager__link" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel', 'class') }}>
  53. <span class="visually-hidden">{{ 'Previous page'|t }}</span>
  54. {% include "@olivero/../images/pager-previous.svg" %}
  55. </a>
  56. </li>
  57. {% endapply %}
  58. {% endif %}
  59. {# Add an ellipsis if there are further previous pages. #}
  60. {% if ellipses.previous %}
  61. <li class="pager__item pager__item--ellipsis" role="presentation">&hellip;</li>
  62. {% endif %}
  63. {# Now generate the actual pager piece. #}
  64. {% for key, item in items.pages %}
  65. {% apply spaceless %}
  66. <li class="pager__item{{ current == key ? ' pager__item--active' : '' }} pager__item--number">
  67. {% if current == key %}
  68. {% set title = 'Current page'|t %}
  69. {% else %}
  70. {% set title = 'Go to page @key'|t({'@key': key}) %}
  71. {% endif %}
  72. {% if current != key %}
  73. <a href="{{ item.href }}" class="pager__link{{ current == key ? ' is-active' }}" title="{{ title }}"{{ item.attributes|without('href', 'title', 'class') }}>
  74. {% endif %}
  75. <span class="visually-hidden">
  76. {{ current == key ? 'Current page'|t : 'Page'|t }}
  77. </span>
  78. {{ key }}
  79. {% if current != key %}
  80. </a>
  81. {% endif %}
  82. </li>
  83. {% endapply %}
  84. {% endfor %}
  85. {# Add an ellipsis if there are further next pages. #}
  86. {% if ellipses.next %}
  87. <li class="pager__item pager__item--ellipsis" role="presentation">&hellip;</li>
  88. {% endif %}
  89. {# Print next item if we are not on the last page. #}
  90. {% if items.next %}
  91. {% apply spaceless %}
  92. <li class="pager__item pager__item--control pager__item--next">
  93. <a href="{{ items.next.href }}" class="pager__link" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel', 'class') }}>
  94. <span class="visually-hidden">{{ 'Next page'|t }}</span>
  95. {% include "@olivero/../images/pager-previous.svg" %}
  96. </a>
  97. </li>
  98. {% endapply %}
  99. {% endif %}
  100. {# Print last item if we are not on the last page. #}
  101. {% if items.last %}
  102. {% apply spaceless %}
  103. <li class="pager__item pager__item--control pager__item--last">
  104. <a href="{{ items.last.href }}" class="pager__link" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title', 'class') }}>
  105. <span class="visually-hidden">{{ 'Last page'|t }}</span>
  106. {% include "@olivero/../images/pager-first.svg" %}
  107. </a>
  108. </li>
  109. {% endapply %}
  110. {% endif %}
  111. </ul>
  112. </nav>
  113. {% endif %}

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