add docs: how to change collection to paginate
This commit is contained in:
parent
bd4034f863
commit
a8b5d9a3cf
2 changed files with 25 additions and 1 deletions
|
|
@ -25,3 +25,26 @@ You can also **hide the number fields** between the previous and next buttons by
|
||||||
paginationNext: 'Next',
|
paginationNext: 'Next',
|
||||||
paginationNumbers: true
|
paginationNumbers: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to change the collection that is paginated (by default `collections.posts`), you must do so in two places: the front matter of the template, `src/pages/blog.md`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
pagination:
|
||||||
|
data: collections.posts
|
||||||
|
```
|
||||||
|
|
||||||
|
and where the pagination component is included: `src/_layouts/blog.njk`:
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
```jinja2
|
||||||
|
<!-- set collection to paginate -->
|
||||||
|
{% set collectionToPaginate = collections.posts %}
|
||||||
|
<!-- if the number of items in the collection is greater than the number of items shown on one page -->
|
||||||
|
{% if collectionToPaginate.length > pagination.size %}
|
||||||
|
<!-- include pagination -->
|
||||||
|
{% include 'components/pagination.njk' %}
|
||||||
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@ pagination:
|
||||||
permalink: 'blog/{% if pagination.pageNumber >=1 %}page-{{ pagination.pageNumber + 1 }}/{% endif %}index.html'
|
permalink: 'blog/{% if pagination.pageNumber >=1 %}page-{{ pagination.pageNumber + 1 }}/{% endif %}index.html'
|
||||||
---
|
---
|
||||||
|
|
||||||
This blog has a pagination of {{ pagination.size }} posts per page.
|
This blog has a pagination of **{{ pagination.size }}** posts per page.
|
||||||
|
The pagination is only shown if there are more posts ({{ collections.posts.length }}) than items per page ({{ pagination.size }}).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue