getgrav / grav-plugin-pagination

Grav Pagination Plugin
https://getgrav.org
MIT License
27 stars 20 forks source link

Get pagination object for any filtered collection #18

Open fvsch opened 8 years ago

fvsch commented 8 years ago

For an article index page that lists blog posts, I was using:

{% for article of page.collection %}
  {# Show link to article #}
{% endfor %}

{% include 'partials/pagination.html.twig' with {
  pagination: page.collection.params.pagination
} %}

But I needed to filter the collection by type because that page contains folders that are not articles. So I switched to:

{% set articles = page.collection.ofType('article') %}
{% for article of articles %}
  {# Show link to article #}
{% endfor %}

{% include 'partials/pagination.html.twig' with {
  pagination: articles.params.pagination
} %}

This work for the links, but not for the pagination which still sees the page count from page.collection().

Shouldn’t .params.pagination represent a pagination object for the collection it’s called from, rather than for the current page?

flaviocopes commented 8 years ago

This is a scenario that should work. Will test and make sure this works.

flaviocopes commented 8 years ago

Thinking twice, I'm starting to think this is not actually expected to work, due to some issues. First, which URL should the plugin redirect to, when clicking a "next" page?

This needs to work withing a collection page.

Would be solved by allowing filtering the type in the page collection itself, as per the other issue you opened.

flaviocopes commented 8 years ago

Another issue was opened to allow such behavior https://github.com/getgrav/grav-plugin-pagination/issues/13 would gladly accept a PR that allows this functionality, provided there's a way to define the base route for the collection, maybe as a parameter to the twig include.

fvsch commented 8 years ago

Thanks for your comments.

For the record the need for this scenario arose from limitations in collection filtering on the content side. I opened Grav bugs https://github.com/getgrav/grav/issues/791 and https://github.com/getgrav/grav/issues/792 on this topic.

It might still be worth to pursue #13 even with this two issues fixed, so I'll look into it later.

Flavio, maybe this issue could be closed as a duplicate of #13?

flaviocopes commented 8 years ago

Let's leave this open too, so we have another request for this feat.

Sogl commented 8 years ago

+1