file pager.html.twig

Default theme implementation to display a pager.

Available variables:

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

Related topics