Paginate
Syntax
PAGE.Paginate COLLECTION [N]
Returns
page.Pager
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 the value of the paginate
setting in your site configuration. The default value is 10
. Override the value in your site configuration by providing a second argument, an integer, when calling the Paginate
method.
You can invoke pagination on the home page template, section
templates, taxonomy
templates, and term
templates.
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" . }}
In the example above, we:
- Build a page collection
- Sort the collection by title
- Paginate the collection, with 7 elements per pager
- Range over the paginated page collection, rendering a link to each page
- Call the internal “pagination” template to create the navigation links between pagers.