diff --git a/src/docs/pagination.md b/src/docs/pagination.md index 69cf395..d40bc97 100644 --- a/src/docs/pagination.md +++ b/src/docs/pagination.md @@ -25,3 +25,26 @@ You can also **hide the number fields** between the previous and next buttons by paginationNext: 'Next', 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 collectionToPaginate = collections.posts %} + +{% if collectionToPaginate.length > pagination.size %} + +{% include 'components/pagination.njk' %} +{% endif %} +``` + +{% endraw %} diff --git a/src/pages/blog.md b/src/pages/blog.md index e357dea..cbd73c1 100644 --- a/src/pages/blog.md +++ b/src/pages/blog.md @@ -8,4 +8,5 @@ pagination: 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 }}).