getgrav/grav-plugin-pagination

pagination option not respected when added to a collection in twig

Closed this issue · 4 comments

ulab commented

I am having an issue with using pagination as shown in Advanced Collections:

{% set options = { items: '@self.descendants', 'filter': {'type': 'blogpost'}, 'order': {'by': 'date', 'dir': 'desc'}, 'limit': 3, 'pagination': true } %}
{% set collection = page.collection(options) %}

In this case the limit is considered, but there is no pagination shown at all unless I set header.content.pagination to true in the page itself.

I am not sure if this is an issue with the Grav documentation, the pagination plugin or my understanding of how to use it.

Coincidentally, I dealt with this a few weeks ago. I confirm this behavior, which also surprised me. The direct insertion into the frontmatter solved the problem.

However, I would also welcome a collection solution that would be universal for all pages using the twig template (e.g. blog, news, etc.).

Per the readme: https://github.com/getgrav/grav-plugin-pagination#twig-pagination-function

a quick example here:

    {% set options = { items: {'@root.descendants':''}, 'order': {'by': 'folder', 'dir': 'asc'}} %}
    {% set my_collection = page.collection(options) %}
    {% do paginate( my_collection, 5 ) %}

    {% for p in my_collection %}

        <ul>
            {% if page.slug == p.slug %}
                <li class="{{ p.slug }} active"><span>{{ p.menu }}</span></li>
            {% else %}
                <li class="{{ p.slug }}"><a href="{{ p.url }}">{{ p.menu }}</a></li>
            {% endif %}
        </ul>

    {% endfor %}

    {% include 'partials/pagination.html.twig' with {'base_url':page.url, 'pagination':my_collection.params.pagination} %}

ulab commented

Thanks, @rhukster.

From: https://learn.getgrav.org/16/content/collections#advanced-collections

{% set options = { items: {'@page.children': '/my/pages'}, 'limit': 5, 'order': {'by': 'date', 'dir': 'desc'}, 'pagination': true } %}
{% set my_collection = page.collection(options) %}

I guess the limit and pagination option at the end of the first line is what threw me under the bus there. Why is it listed if it has no effect?

The example on https://learn.getgrav.org does not contain the code needed for pagination:
```
...
{% do paginate( my_collection, 5 ) %}
```
But this is described in detail in the README.md of plugin. I will send Pull request with the addition of code.

The example by @rhukster on https://github.com/getgrav/grav-plugin-pagination#twig-pagination-function contain the full code needed for pagination and is described in detail in the README.md of plugin too.