[solved] Pagination: problem with selecting multiple page types

I have postURL = blog defined in the config file. I can print {{ .Site.Params.postURL }} and see blog come up on the page. However, I can’t seem to get it to work in an IN clause.

{{ $pag := .Paginate (first 5 (where .Data.Pages “Type” “in” (slice “{{.Site.Params.postURL}}” “project”) )) }}

If I change it to “blog” it works fine. To test it out, I changed the second value going into slice to “project” as shown above and I can see posts from projects come up.

For some reason when I use the param from config as an input to slice it doesn’t like it. There are no errors. pages form projects come up but none from blog show up.

I have restarted hugo server and tested it as well.

What am I doing wrong?

Remove the quotes around {{.Site.Params.postURL}}

I tried that. It won’t even compile; throws following error:

template.go:472: template: theme/index.html:13: unexpected "{" in operand

And the brackets, I should have added:


thanks for the reply.

I had tried all those combinations. Without the brackets, it compiles fine but doesn’t work. Only the project type pages come up.

That did the trick. I had removed the entry from config hence it didn’t work! Thanks again!

How to get this to work here:

{{ $paginator := .Paginate (where (where .Pages "type" "in" (slice "type-1" "type-2" "type-3")).ByDate.Reverse "Params.hidden" "!=" true) 10 }}
    {{ range (.Paginator 10).Pages }}

Just throws an error:

Error: Error building site: failed to render pages: render of “home” failed: “c:\Hugo\sites\build-directory\layouts_default\list.html:152:35”: execute of template failed: template: _default\list.html:152:35: executing “main” at <where .Pages "sectio…>: error calling where: section isn’t a field of struct type *hugolib.Page

Big thanks if you can share the solve.

See Listing multiple types on home page

Closing this.