Comment on page
Pagination
The pagination object is returned on listing pages, usually in the
{{ pages.pagination }}
field.The pagination object has the following variables and functions available. In the following examples we assume the pagination object is
{{ pagination }}
Return current page.
{{ pagination.page }}
Return total number of results.
{{ pagination.totalResults }}
Return total number of pages available.
{{ pagination.totalPages }}
Return number of results per page.
{{ pagination.resultsPerPage }}
Return result number for first result on this page.
{{ pagination.from }}
Return result number for last result on this page.
{{ pagination.to }}
This is page {{ pagination.page }}, displaying results {{ pagination.from }}-{{ pagination.to }}
If pagination is on page 2 with 20 results per page, this will display:
This is page 2, displaying results 11-20
Are we on the first page of pagination?
<div data-gb-custom-block data-tag="if"></div>
Do something
</div>
Output the first page of pagination. This is normally 1.
{{ pagination.first }}
Are we on the last page of pagination?
<div data-gb-custom-block data-tag="if"></div>
Do something
</div>
Output the last page of pagination.
{{ pagination.last }}
Return the previous page number, or 1 if we are on the first page.
{{ pagination.previous }}
Return the next page number, or the last page number if we are already on the last page.
{{ pagination.next }}
This returns an array of a set of page numbers to display in pagination. It defaults to showing 5 pages at a time, though you can customise this by altering the
$maxPages
value.For example, using the default 5 page links for a pagination result set with 50 pages you would get the following results:
- Page 1:
[1,2,3,4,5]
- Page 2:
[1,2,3,4,5]
- Page 6:
[4,5,6,7,8]
- Page 45:
[45,46,47,48,49]
- Page 47:
[46,47,48,49,50]
- Page 50:
[46,47,48,49,50]
See an example at
templates/includes/pagination.html.twig
When calling this template you need to pass the pagination object and the page route you want to generate for pagination links. For example:
{{ include('includes/pagination.html.twig', {'pagination': pages.pagination, 'route': 'news_list'}) }}
Last modified 9mo ago