Hugo paginator range for subdirectories?

Hello guys,
my plan is to show all posts under a specific sub-website called /posts there should be listed all posts from “content/posts/subdirectory/post1/_index.md”. The reason for the subdirectory is to have a knowledgebase more organized with “series”. I have a list which works fine for my Problem:

{{ range (where .Site.RegularPages "Section" "posts") }}
   <a href="{{.Permalink}}">{{- .Title -}}</a>
{{ end }}

But if i use this list 1. i can’t view all pages of a specific subdirectory for example on the site: “content/posts/subdirectory/” and 2. my list-pagination to split the posts up is also broken.

If i just range the paginator pages only single posts will be displayed, so the subdirectory listing works fine but not for the /posts overview, there will be nothing:

{{ range .Paginator.Pages }}

Do you know any way to include websites of a sub-sub-directory to the pagination or know a workaround which also works with the pagination?

Regards
OjunbamO

I’m not sure I understand the problem, but:

  • I assume you know about the .Paginate method? You can do .Paginate (where .Site.RegularPages "Section" "posts")
  • Also, if you do $post1.Pages or $post1.RegularPages you will get only the pages in that section.

There is an open issue about adding some recursive helper methods that I hope I or someone else will get to soon, which would enable to rewrite:

{{ $posts := (where .Site.RegularPages "Section" "posts") }}

To

{{ $posts := (site.GetPage "post").RegularPagesRecursive }}

Etc.

First thanks for you’re answer.
I tried to use .Paginate but it always results in an error.

summarized:
I just need to iterate over all pages in a specific subdirectory with .Paginate and list all posts of the “Sub-Sub directorys”.

First I was using {{ range .Paginator.Pages }} but on the /posts list section it showed nothing. For the list /posts/whateverseries it worked very well.

Regards

So, instead of looking for non-existent solutions, you should get the working one working. What is the error?

If I try to use your solution, it just says that RegularPagesRecursive isn’t existed like. Also not existend in the docs.

render of "section" failed: "layouts/_default/list.html:103:31": execute of template failed: template: _default/list.html:103:31: executing "main" at <"hub">: can't evaluate field RegularPagesRecursive in type page.Page
render of "section" failed: "layouts/_default/list.html:103:31": execute of template failed: template: _default/list.html:103:31: executing "main" at <"hub">: can't evaluate field RegularPagesRecursive in type page.Page
Rebuild failed:

Failed to render pages: render of "section" failed: "layouts/_default/list.html:103:31": execute of template failed: template: _default/list.html:103:31: executing "main" at <"hub">: can't evaluate field RegularPagesRecursive in type page.Page

and just {{ .Paginate.Pages }} says:

render of "section" failed: "layouts/_default/list.html:103:16": execute of template failed: template: _default/list.html:103:16: executing "main" at <.Paginate.Pages>: wrong number of args for Paginate: want at least 1 got 0
render of "section" failed: "layouts/_default/list.html:103:16": execute of template failed: template: _default/list.html:103:16: executing "main" at <.Paginate.Pages>: wrong number of args for Paginate: want at least 1 got 0
Rebuild failed:

Failed to render pages: render of "section" failed: "layouts/_default/list.html:103:16": execute of template failed: template: _default/list.html:103:16: executing "main" at <.Paginate.Pages>: wrong number of args for Paginate: want at least 1 got 0

OK. That was me talking about a “future method” (it’s planned, but it does not exist).

1 Like

Yea I think that would fix my problem.

I just build a little workaround:

{{ if in .Permalink "/posts/" }}
	{{ range (where .Site.RegularPages "Section" "posts") }}
		<a href="{{.Permalink}}">{{- .Title -}}</a>
	{{ end }}			
{{ else }}
	{{ range .Paginator.Pages }}
		<a href="{{.Permalink}}">{{- .Title -}}</a>
	{{ end }}
{{ end }}

The only problem with this now, is that it’ll show all entries of /posts on all list series: /posts/whateverseries + the pagination won’t work (but I think thats tolerable)

Does anyone know how to build a little workaround for that? With an extended if statement or something?

Regards