I’m not really sure what it is you are wanting to paginate. Here’s some notes that might help with how to think about pagination:
- What are the pages that you want to include in the “Set of pages to paginate” ?
- How do you want to divide these pages into “Paginator Pages” ?
So, consider your context. You are in term.html, which is the layout that gets called when you go to yoursite.com/tags/lorem/. You can see this by putting “This is term.html” in the term.html layout and checking that this does appear in the correct place.
Slightly modifying the example here: Pagination | Hugo
This is one of the simplest code snippets you can use that will give you pagination:
{{ $paginator := .Paginate .Pages }}
{{ range $paginator.Pages }}
{{ .Title }}
{{ end }}
{{ template "_internal/pagination.html" . }}
Breaking this down:
{{ $paginator := .Paginate .Pages }}
^ ^ Set of pages to paginate
Divide set of pages into Paginator Pages
This creates a Paginator by calling .Paginate on .Pages. Here, .Pages is the “Set of pages to paginate”.
Other examples might be something like (where .Pages "Section" "posts") if you want to restrict the set to only those from under /posts/:
{{ $paginator := .Paginate (where .Pages "Type" "posts") }}
Going back to your term.html.
Given tags/lorem/ as an example, the .Pages in term.html is the set of pages that have tags: "lorem" defined.
{{ range $paginator.Pages }}
{{ .Title }}
{{ end }}
This part of the snippet renders the subset of .Pages that are in the current .Paginator page. So, if you have 9 .Pages, with a pagination size of 2, yoursite.com/tags/lorem/ will contain the first 2 pages in .Pages, and yoursite.com/tags/lorem/page/5/ will contain the last 1.
{{ template "_internal/pagination.html" . }}
Finally, this is what renders the pagination navigation. Here, I am using the built in one, but you are of course able to write your own template.
Going back to the beginning: firstly, decide what subset of pages you want to paginate. Start simple: .Paginate .Pages, then play around with getting only a subset of this, using where and other qualifiers.
I hope this helps, and has not made things even more confusing!