Pagination for sections

I have a few subsections inside a section and the leyout is like below:

content/
├── docs/
│ ├── _index.md
│ ├── demo-1/
│ │ ├── _index.md
│ │ ├── chapter1.md
│ │ ├── chapter2.html
│ ├── demo-2/
│ │ ├── _index.md
│ │ ├── chapter1.html
│ │ ├── chapter2.html
│ ├── ……

And I want to paginate those subsections in section docs. I have searched the forum and I find a solution like:

{{ $ps := .Paginate .Sections }}
{{ range $ps.Pages }}
    {{ .Title }}
{{ end }}

But when I use this, there is a Pager indeed. However, when I print $ps.Pages, the result is Pages(0). There is no pages in the Pager. And if I print .Sections, it has the right info I need. It seems that the solution is not available now. So I am looking for an avaliable solution.

Btw, my Hugo version is v0.74.3 extended.

Thank you for advanced.

Hi there,

Do you have your repo somewhere we can have a look at? It is easier to help you if we can replicate what you are doing.

I get pages as a result on testing with my sample site.

@pointyfar Hi, thank you for your reply. I have uploaded a demo repo of this problem here.

The relevant code is in themes/eureka/layouts/docs/doc_list.html Line12 and 15.

Thank you for your help!

You already have a .Paginator call earlier in your layout: https://github.com/wangchucheng/pagination-demo/blob/master/themes/eureka/layouts/partials/schema_node.html#L1

From the docs: https://gohugo.io/templates/pagination/#list-paginator-pages

If you call .Paginator or .Paginate multiple times on the same page, you should ensure all the calls are identical. Once either .Paginator or .Paginate is called while generating a page, its result is cached, and any subsequent similar call will reuse the cached result. This means that any such calls which do not match the first one will not behave as written.

Thanks for the solution. It works well now!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.