Say that I have a set of mostly-alike pages divided into subsections. All the pages have the same type, but individual items can be categorized differently, hence dropping them into subsections:
something like that. I can get the site to generate with the sub-pages put together, paginating etc correctly … except the books page is empty. I’d like to be able to either: list all books from all subsections, or, filter the list to things with featured: true
in the frontmatter, and I can’t quite figure out how to go about doing that.
It seems like there’s only one list.html
allowed for the overall type, and attempting to override the $paginator
inside an _index.md
just results in the line being echoed on page. Anyone have any ideas on this?
- Create a layout at
layouts/books/list.html
.
- To add content or front matter to your rendered page, you’ll need to create a content file at
content/books/_index.md
.
- You can use
.Data.Pages
, which will automatically pull from all the pages in that section.
- Use the
where
keyword to filter…
{{range where .Data.Pages ".Params.featured" true}}
{{ end }}
If not, try "Params.featured"
…sorry, can’t test right now…
You can customize your list.html as you want per section with something like:
{{ if eq .Section "non-fiction" }}
.....
{{ end }}
Check out the official demo of Hugo nested sections: http://hugotest.bep.is/
I haven’t experimented with nested sections yet, but in Hugo /section/
is an alias of type
.
So to render all posts in a main section (including the ones in nested sections) do this:
{{ range $i, $e := (where .Site.Pages “Type” “non-fiction”) }}
…
{{ end }}