2017-10-01 03:51:43 +00:00
|
|
|
|
+++
|
|
|
|
|
title = "Pagination"
|
|
|
|
|
weight = 30
|
|
|
|
|
+++
|
|
|
|
|
|
2019-05-20 09:30:41 +00:00
|
|
|
|
Two things can get paginated: a section and a taxonomy term.
|
2018-07-16 08:54:05 +00:00
|
|
|
|
|
2019-08-15 20:14:53 +00:00
|
|
|
|
Both kinds get a `paginator` variable of the `Pager` type, on top of the common variables mentioned in the
|
|
|
|
|
[overview page](@/documentation/templates/overview.md):
|
2017-10-01 03:51:43 +00:00
|
|
|
|
|
|
|
|
|
```ts
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// How many items per pager
|
2017-10-01 03:51:43 +00:00
|
|
|
|
paginate_by: Number;
|
2018-09-30 21:49:32 +00:00
|
|
|
|
// The base URL for the pagination: section permalink + pagination path
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// You can concatenate an integer with that to get a link to a given pagination pager.
|
2018-09-30 21:49:32 +00:00
|
|
|
|
base_url: String;
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// How many pagers in total
|
2018-09-30 21:49:32 +00:00
|
|
|
|
number_pagers: Number;
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// Permalink to the first pager
|
2017-10-01 03:51:43 +00:00
|
|
|
|
first: String;
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// Permalink to the last pager
|
2017-10-01 03:51:43 +00:00
|
|
|
|
last: String;
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// Permalink to the previous pager, if there is one
|
2017-10-01 03:51:43 +00:00
|
|
|
|
previous: String?;
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// Permalink to the next pager, if there is one
|
2017-10-01 03:51:43 +00:00
|
|
|
|
next: String?;
|
2019-08-13 17:19:43 +00:00
|
|
|
|
// All pages for the current pager
|
2017-10-01 03:51:43 +00:00
|
|
|
|
pages: Array<Page>;
|
2021-07-19 18:56:22 +00:00
|
|
|
|
// Which pager are we on, 1-indexed
|
2017-10-01 03:51:43 +00:00
|
|
|
|
current_index: Number;
|
2021-05-31 07:21:18 +00:00
|
|
|
|
// Total number of pages across all the pagers
|
2019-10-28 11:55:49 +00:00
|
|
|
|
total_pages: Number;
|
2017-10-01 03:51:43 +00:00
|
|
|
|
```
|
2018-11-29 19:24:45 +00:00
|
|
|
|
|
2021-03-11 18:35:54 +00:00
|
|
|
|
**The variable will not be defined if `paginate_by` is not set to a positive number.**
|
|
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
|
A pager is a page of the pagination; if you have 100 pages and paginate_by is set to 10, you will have 10 pagers each
|
|
|
|
|
containing 10 pages.
|
2019-08-13 17:19:43 +00:00
|
|
|
|
|
2018-11-29 19:24:45 +00:00
|
|
|
|
## Section
|
|
|
|
|
|
|
|
|
|
A paginated section gets the same `section` variable as a normal
|
2019-07-11 08:00:35 +00:00
|
|
|
|
[section page](@/documentation/templates/pages-sections.md#section-variables)
|
2019-05-20 09:30:41 +00:00
|
|
|
|
minus its pages. The pages are instead in `paginator.pages`.
|
2018-11-29 19:24:45 +00:00
|
|
|
|
|
|
|
|
|
## Taxonomy term
|
|
|
|
|
|
2019-05-20 09:30:41 +00:00
|
|
|
|
A paginated taxonomy gets two variables aside from the `paginator` variable:
|
2018-11-29 19:24:45 +00:00
|
|
|
|
|
|
|
|
|
- a `taxonomy` variable of type `TaxonomyConfig`
|
|
|
|
|
- a `term` variable of type `TaxonomyTerm`.
|
|
|
|
|
|
2019-05-27 12:35:14 +00:00
|
|
|
|
See the [taxonomies page](@/documentation/templates/taxonomies.md) for a detailed version of the types.
|
2021-01-09 09:26:32 +00:00
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
|
|
Here is an example from a theme on how to use pagination on a page (`index.html` in this case):
|
|
|
|
|
|
|
|
|
|
```jinja2
|
|
|
|
|
<div class="posts">
|
|
|
|
|
{% for page in paginator.pages %}
|
|
|
|
|
<article class="post">
|
|
|
|
|
{{ post_macros::title(page=page) }}
|
|
|
|
|
<div class="post__summary">
|
|
|
|
|
{{ page.summary | safe }}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="read-more">
|
|
|
|
|
<a href="{{ page.permalink }}">Read more...</a>
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
{% endfor %}
|
|
|
|
|
</div>
|
|
|
|
|
<nav class="pagination">
|
|
|
|
|
{% if paginator.previous %}
|
|
|
|
|
<a class="previous" href="{{ paginator.previous }}">‹ Previous</a>
|
|
|
|
|
{% endif %}
|
|
|
|
|
{% if paginator.next %}
|
|
|
|
|
<a class="next" href="{{ paginator.next }}">Next ›</a>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</nav>
|
2021-03-11 18:35:54 +00:00
|
|
|
|
```
|