How to implement: Go To Page: < 1 2 3 4 5 6 7 8 9 10 >?

How do I implement something like this:

Go To Page: < 1 2 3 4 5 6 7 8 9 10 >

where each page would contain, say 10 posts?
(This would be something smilar to Google search result web page, where each page would have a certain number of results - I can click through to “2”, “3”, “4”, and so on…)

The closest documentation I’m seeing is Pagination, but the instruction isn’t clear.

It seems I have to do a global count of all the posts, cache it in a global variable, and that use that to generate all the pages. Is this the way to do it? Is there an easier way? Any ready or sample code?

It’s easy to implement with the data found in the link you gave.
number_pagers correspond to 10 in this case, you get the current page in current_index. The arrows are shown in the example in the page.
I guess we could add the numbers to the example on the docs site.

1 Like

Also trying to figure this out.

I can only seem to loop collections in tera. I was expecting to either loop an array of pagers or write a loop that incremented i up to number_pages and manipulate a string to form the links based on the index.

I’ve probably missed something obvious but any further advice would be appreciated.

Sorry to spam this old thread but for anyone who was having the same problem there’s a good code example in this theme.

The part I was missing was the range function. Something like this…

{%- for i in range(start=1, end=number_pagers + 1) -%}
  DO STUFF
{% endfor %}