1

I am building a pagination layout limiting the content to 10 because, well, it makes sense to break down large amounts of content to smaller chunks.

But as there is so much, a user might want to toggle how many they want to see. But because the pagination limit is done in the twig variables, is there a built in method for updating this on user interactions?

Standard CraftCMS pagination code:

{% paginate craft.entries.section(entry.slug).order('postDate desc').with: ['image'].limit(10) as pageInfo, pageItems %}

Cheers

1 Answer 1

2

You could create a form/a link with the limit and add the parameter in your $_GET request or as a segment to your url. This is just an example how to use it.

How many Entries would you like to get?
<a href="/?limit=10">10</a>
<a href="/?limit=20">20</a>
<a href="/?limit=30">30</a>

Then you can fetch this parameter

{% set limit = craft.request.getQuery('limit', 10) %}
{% paginate craft.entries.section(entry.slug).order('postDate desc').with: ['image'].limit(limit) as pageInfo, pageItems %}

Of course you have to attach this parameter to your paginate links as well

{% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}?limit={{ limit }}">Previous Page</a>{% endif %}

There are definitely better solutions but they require more time and more effort and a plugin/php but this would be the easiest solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.