Skip to content

Commit c01cb7f

Browse files
committed
DIGITAL-243: Update pagination markup
1 parent 3763370 commit c01cb7f

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{#
2+
/**
3+
* @file
4+
* Default theme implementation 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+
* @ingroup themeable
34+
*/
35+
#}
36+
{% if items %}
37+
<nav role="navigation" aria-labelledby="{{ heading_id }}">
38+
<{{ pagination_heading_level }} id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</{{ pagination_heading_level }}>
39+
<ul class="pagination">
40+
{# Print first item if we are not on the first page. #}
41+
{% if items.first %}
42+
<li class="pagination-first">
43+
<a href="{{ items.first.href }}" aria-label="{{ 'First page'|t }}">
44+
<svg
45+
class="usa-icon dg-icon dg-icon--large"
46+
aria-hidden="true"
47+
focusable="false"
48+
role="img"
49+
>
50+
<use
51+
xlink:href="{{ drupal_url('/' ~ active_theme_path() ~ '/static/digitalgov/img/sprite.svg#first_page') }}"
52+
></use>
53+
</svg>
54+
</a>
55+
</li>
56+
{% endif %}
57+
{# Print previous item if we are not on the first page. #}
58+
{% if items.previous %}
59+
<li class="pagination-previous">
60+
<a href="{{ items.previous.href }}" aria-label="{{ 'Previous page'|t }}">
61+
<svg
62+
class="usa-icon dg-icon dg-icon--standard"
63+
aria-hidden="true"
64+
focusable="false"
65+
role="img"
66+
>
67+
<use
68+
xlink:href="{{ drupal_url('/' ~ active_theme_path() ~ '/static/digitalgov/img/sprite.svg#arrow_back') }}"
69+
></use>
70+
</svg>
71+
</a>
72+
</li>
73+
{% endif %}
74+
{# Now generate the actual pager piece. #}
75+
{% for key, item in items.pages %}
76+
<li class="page {{ current == key ? ' active' : '' }}">
77+
<a href="{{ item.href }}" class="pagination__link">
78+
{{- key -}}
79+
</a>
80+
</li>
81+
{% endfor %}
82+
{# Print next item if we are not on the last page. #}
83+
{% if items.next %}
84+
<li class="pagination-next">
85+
<a href="{{ items.next.href }}" aria-label="{{ 'Next page'|t }}">
86+
<svg
87+
class="usa-icon dg-icon dg-icon--standard"
88+
aria-hidden="true"
89+
focusable="false"
90+
role="img"
91+
>
92+
<use
93+
xlink:href="{{ drupal_url('/' ~ active_theme_path() ~ '/static/digitalgov/img/sprite.svg#arrow_forward') }}"
94+
></use>
95+
</svg>
96+
</a>
97+
</li>
98+
{% endif %}
99+
{# Print last item if we are not on the last page. #}
100+
{% if items.last %}
101+
<li class="pagination-last">
102+
<a href="{{ items.last.href }}" aria-label="{{ 'Last page'|t }}">
103+
<svg
104+
class="usa-icon dg-icon dg-icon--large"
105+
aria-hidden="true"
106+
focusable="false"
107+
role="img"
108+
>
109+
<use
110+
xlink:href="{{ drupal_url('/' ~ active_theme_path() ~ '/static/digitalgov/img/sprite.svg#last_page') }}"
111+
></use>
112+
</svg>
113+
</a>
114+
</li>
115+
{% endif %}
116+
</ul>
117+
</nav>
118+
{% endif %}

0 commit comments

Comments
 (0)