uswds-8.x-2.1-rc1/templates/navigation/pager.html.twig
templates/navigation/pager.html.twig
{#
/**
* @file
* Theme override to display a pager using USWDS class names.
*
* 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 template_preprocess_pager()
*/
#}
{% if items %}
<nav class="usa-pagination" role="navigation" aria-labelledby="{{ heading_id }}">
<div id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</div>
<ul class="usa-pagination__list pager__items js-pager__items">
{# Print Previous link if we are not on the first page. #}
{% if items.previous %}
<li class="usa-pagination__item usa-pagination__arrow">
<a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel') }}>
<svg class="usa-icon" aria-hidden="true" role="img">
<use xlink:href="/{{ directory }}/assets/img/sprite.svg#navigate_before"></use>
</svg>
<span class="usa-pagination__link-text"> {{ 'Previous'|t }} </span>
</a>
</li>
{% endif %}
{# Print first item before the previous ellipsis. #}
{% if items.first %}
<li class="usa-pagination__item usa-pagination__page-no">
<a href="{{ items.first.href }}" title="{{ 'Go to page 1'|t }}"{{ items.first.attributes|without('href', 'title') }}>
1
</a>
</li>
{% endif %}
{# Add a previous ellipsis if needed. #}
{% if ellipses.previous %}
<li class="usa-pagination__item usa-pagination__overflow" role="presentation">…</li>
{% endif %}
{# Now generate the actual pager piece. #}
{% for key, item in items.pages %}
<li class="usa-pagination__item usa-pagination__page-no">
{% if current == key %}
{% set title = 'Current page'|t %}
{% else %}
{% set title = 'Go to page @key'|t({'@key': key}) %}
{% endif %}
<a href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title') }}>
<span class="visually-hidden">
{{ current == key ? 'Current page'|t : 'Page'|t }}
</span>
{{- key -}}
</a>
</li>
{% endfor %}
{# Add a next ellipsis if needed. #}
{% if ellipses.next %}
<li class="usa-pagination__item usa-pagination__overflow" role="presentation">…</li>
{% endif %}
{# Print last item after the next ellipsis if needed. #}
{% if items.last %}
<li class="usa-pagination__item usa-pagination__page-no">
<a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title') }}>
{{ items.last.number }}
</a>
</li>
{% endif %}
{# Print Next link if we are not on the last page. #}
{% if items.next %}
<li class="usa-pagination__item usa-pagination__arrow">
<a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel') }}>
<span class="usa-pagination__link-text"> {{ 'Next'|t }} </span>
<svg class="usa-icon" aria-hidden="true" role="img">
<use xlink:href="/{{ directory }}/assets/img/sprite.svg#navigate_next"></use>
</svg>
</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
