1

Just a quicky regarding pagination. I have a paginated results list with a limit of 20 results in a page.

I'm wondering how I owuld go about making a pagination that shows the number of results on the next page.

i.e. If I have 105 results, the pagination link says 'next 20 results', up to the fifth page, which would then say 'next 5 results'.

Not sure if there is an easier way to do it other than a load of maths to work it out.

Thanks!

1

Not sure about a load of math, but if you've got pageInfo setup like in the docs, should be something like this:

{% set totalPages = pageInfo.totalPages %}
{% set itemsPerPage = 20 %}
{% set currentPage = pageInfo.currentPage %}
{% set totalItems = pageInfo.total %}

{% set wholeItems = (totalPages - 1) * itemsPerPage %}
{% set remainderItems = totalItems - wholeItems %}

{% if currentPage == totalPages - 1 %}
    Next {{ remainderItems }} items.
{% else %}
    Next {{ itemsPerPage }} items.
{% endif %}
  • Yup, that's what I meant by maths! 😉 juts wondered if there was an easier way, but I'll roll with your suggestion! Thanks! – shorn Jan 21 '17 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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