Skip to content
Snippets Groups Projects
Commit f230027a authored by Vladimir Roudakov's avatar Vladimir Roudakov Committed by Vladimir Roudakov
Browse files

Issue #3215419 by VladimirAus: Improve views pages based on documentation

parent 1f079c19
Branches
Tags
No related merge requests found
......@@ -4,6 +4,7 @@
* 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.
......@@ -29,20 +30,14 @@
* @see template_preprocess_pager()
*/
#}
{%
set btn_classes = [
'btn',
'btn-light',
]
%}
{% if items %}
<nav class="pager" role="toolbar" aria-labelledby="pagination-heading">
<h4 id="pagination-heading" class="visually-hidden">{{ 'Pagination'|t }}</h4>
<ul class="pager__items js-pager__items btn-group" role="group">
<nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
<h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
<ul class="pagination pager__items js-pager__items">
{# Print first item if we are not on the first page. #}
{% if items.first %}
<li class="pager__item pager__item--first {{ btn_classes|join(' ') }}">
<a href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}" {{ items.first.attributes|without('href', 'title') }}>
<li class="page-item pager__item--first">
<a href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}"{{ items.first.attributes.addCLass('page-link')|without('href', 'title') }}>
<span class="visually-hidden">{{ 'First page'|t }}</span>
<span aria-hidden="true">{{ items.first.text|default('« First'|t) }}</span>
</a>
......@@ -50,8 +45,8 @@
{% endif %}
{# Print previous item if we are not on the first page. #}
{% if items.previous %}
<li class="pager__item pager__item--previous {{ btn_classes|join(' ') }}">
<a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel') }}>
<li class="page-item pager__item--previous">
<a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes.addCLass('page-link')|without('href', 'title', 'rel') }}>
<span class="visually-hidden">{{ 'Previous page'|t }}</span>
<span aria-hidden="true">{{ items.previous.text|default('‹ Previous'|t) }}</span>
</a>
......@@ -59,17 +54,19 @@
{% endif %}
{# Add an ellipsis if there are further previous pages. #}
{% if ellipses.previous %}
<li class="pager__item pager__item--ellipsis {{ btn_classes|join(' ') }}" role="presentation">&hellip;</li>
<li class="page-item disabled">
<span class="page-link">&hellip;</span>
</li>
{% endif %}
{# Now generate the actual pager piece. #}
{% for key, item in items.pages %}
<li class="btn btn-secondary pager__item{{ current == key ? ' active' : '' }} {{ btn_classes|join(' ') }}">
<li class="page-item{{ current == key ? ' is-active active' : '' }}"{{ current == key ? ' aria-current="page"' : '' }}>
{% 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') }}>
<a href="{{ item.href }}" title="{{ title }}"{{ item.attributes.addCLass('page-link')|without('href', 'title') }}>
<span class="visually-hidden">
{{ current == key ? 'Current page'|t : 'Page'|t }}
</span>
......@@ -79,12 +76,14 @@
{% endfor %}
{# Add an ellipsis if there are further next pages. #}
{% if ellipses.next %}
<li class="pager__item pager__item--ellipsis {{ btn_classes|join(' ') }}" role="presentation">&hellip;</li>
<li class="page-item disabled">
<span class="page-link">&hellip;</span>
</li>
{% endif %}
{# Print next item if we are not on the last page. #}
{% if items.next %}
<li class="pager__item pager__item--next {{ btn_classes|join(' ') }}">
<a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel') }}>
<li class="page-item pager__item--next">
<a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes.addCLass('page-link')|without('href', 'title', 'rel') }}>
<span class="visually-hidden">{{ 'Next page'|t }}</span>
<span aria-hidden="true">{{ items.next.text|default('Next ›'|t) }}</span>
</a>
......@@ -92,8 +91,8 @@
{% endif %}
{# Print last item if we are not on the last page. #}
{% if items.last %}
<li class="pager__item pager__item--last {{ btn_classes|join(' ') }}">
<a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title') }}>
<li class="page-item pager__item--last">
<a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes.addCLass('page-link')|without('href', 'title') }}>
<span class="visually-hidden">{{ 'Last page'|t }}</span>
<span aria-hidden="true">{{ items.last.text|default('Last »'|t) }}</span>
</a>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment