Paginate _all_ the pages within a folder, including all the files within subdirectories

I’ve been building a theme for my blog and it has been a delight so far. I love how Hugo has just the right balance between complexity and usefulness. I’ve been trying for a few days now to solve the following problem but to no avail.

Is it possible to Paginate ALL the pages within a folder, including all the files within subdirectories, and not just the files directly insider this folder?

Since the taxonomies in Hugo are flat I’ve a nested file structure (I’m anal about organization) which I then loop through, for instance, for producing menus. Currently I’ve the following directory structure

++ Book_1
++ Book_2

I’m trying the following code (inside list.html). This is the entire list.html, there are no other lines.

{{$.Scratch.Add "list_pages" .Pages}}

{{ range .Sections }}
    {{$.Scratch.Add "list_pages" .Pages}}
{{ end }}

{{$paginate := .Paginate ($.Scratch.Get "list_pages")}}

However here I get the error:

ERROR 2017/12/30 11:51:21 Error while rendering "home": template: theme/_default/list.html:12:15: executing "theme/_default/list.html" at <.Paginate>: error calling Paginate: invoked multiple times with different arguments

Upon searching the discussion boards I THINK this is happening because I’m calling .Pages which is somehow setting the $paginate (which I understand is static). So I guess the bottomline is:

Is it possible to get the list of pages without setting $paginate? Or is it the case that $paginate is preset in some sense and it cannot be used to Paginate user-defined arrays?


No, you have a previous reference to .Paginator. Or .Paginate with a different set of pages (that is usually a partial’s “fault”; harder to spot). I would assume that what you want should be possible without .Scratch, but I haven’t thought hard about it …


To see if this is the case I created a dummy theme with ONLY a list.html file containing those 5 lines of code and I still get the same error that .Paginator is being called twice with different arguments. (My Hugo version is v0.31.1 in case it matters.)

The error message is pretty clear. Not sure what makes it different in your case.