Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'

This commit is contained in:
Bjørn Erik Pedersen
2025-04-10 13:04:51 +02:00
987 changed files with 12379 additions and 14083 deletions

View File

@@ -3,40 +3,31 @@ title: Paginate
description: Paginates a collection of pages.
categories: []
keywords: []
action:
related:
- methods/page/Paginator
returnType: page.Pager
signatures: ['PAGE.Paginate COLLECTION [N]']
params:
functions_and_methods:
returnType: page.Pager
signatures: ['PAGE.Paginate COLLECTION [N]']
---
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.
By default, the number of elements on each pager is determined by your [site configuration]. The default is `10`. Override that value by providing a second argument, an integer, when calling the `Paginate` method.
[site configuration]: /getting-started/configuration/#pagination
{{% note %}}
There is also a `Paginator` method on `Page` objects, but it can neither filter nor sort the page collection.
The `Paginate` method is more flexible.
{{% /note %}}
> [!note]
> There is also a `Paginator` method on `Page` objects, but it can neither filter nor sort the page collection.
>
> The `Paginate` method is more flexible.
You can invoke pagination on the [home template], [section templates], [taxonomy templates], and [term templates].
[home template]: /templates/types/#home
[section templates]: /templates/types/#section
[taxonomy templates]: /templates/types/#taxonomy
[term templates]: /templates/types/#term
{{< code file=layouts/_default/list.html >}}
```go-html-template {file="layouts/_default/list.html"}
{{ $pages := where .Site.RegularPages "Section" "articles" }}
{{ $pages = $pages.ByTitle }}
{{ range (.Paginate $pages 7).Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}
{{< /code >}}
```
In the example above, we:
@@ -46,6 +37,11 @@ In the example above, we:
1. Range over the paginated page collection, rendering a link to each page
1. Call the embedded pagination template to create navigation links between pagers
{{% note %}}
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.
{{% /note %}}
> [!note]
> 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.
[home template]: /templates/types/#home
[section templates]: /templates/types/#section
[site configuration]: /configuration/pagination/
[taxonomy templates]: /templates/types/#taxonomy
[term templates]: /templates/types/#term