| 1 |
--- |
| 2 |
title: Paginator |
| 3 |
description: Returns a pager created by paginating the collection of regular pages received in context. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: page.Pager |
| 9 |
signatures: [PAGE.Paginator] |
| 10 |
--- |
| 11 |
|
| 12 |
Pagination is the process of splitting a list page into two or more pagers, where each pager contains a subset of the page collection and navigation links to other pagers. |
| 13 |
|
| 14 |
The number of elements on each pager is determined by your [project configuration][]. The default is `10`. |
| 15 |
|
| 16 |
You can invoke pagination in [home][], [section][], [taxonomy][], and [term][] templates. Each of these receives a collection of regular pages in [context](g). When you invoke the `Paginator` method, it paginates the page collection received in context. |
| 17 |
|
| 18 |
```go-html-template {file="layouts/section.html"} |
| 19 |
{{ range .Paginator.Pages }} |
| 20 |
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2> |
| 21 |
{{ end }} |
| 22 |
{{ partial "pagination.html" . }} |
| 23 |
``` |
| 24 |
|
| 25 |
In the example above, the embedded pagination template creates navigation links between pagers. |
| 26 |
|
| 27 |
> [!NOTE] |
| 28 |
> Although simple to invoke, with the `Paginator` method you can neither filter nor sort the page collection. It acts upon the page collection received in context. |
| 29 |
> |
| 30 |
> The [`Paginate`][] method is more flexible, and strongly recommended. |
| 31 |
|
| 32 |
> [!NOTE] |
| 33 |
> Please note that the results of pagination are cached. Once you have invoked either the `Paginator` or `Paginate` method, the paginated collection is immutable. Additional invocations of these methods will have no effect. |
| 34 |
|
| 35 |
[`Paginate`]: /methods/page/paginate/ |
| 36 |
[home]: /templates/types/#home |
| 37 |
[project configuration]: /configuration/pagination/ |
| 38 |
[section]: /templates/types/#section |
| 39 |
[taxonomy]: /templates/types/#taxonomy |
| 40 |
[term]: /templates/types/#term |