Hello again @hendry
This is kind of a pretty basic Page filtering question.
There are a couple of challenges in the sense that you want to list all pages both Regular and Nested Section lists below a given Section. Basically you want to hide the .FirstSection
i.e. /tips/
from the rendered list.
The way I would go about it, would be to use Hugo’s Build Options to disable the listing of the .FirstSection
page /tips/
.
So in /content/tips/_index.md
I would add the following:
_build:
list: never
Then in the template under /layouts/_default/list.html
I would change the range
function to:
range where .Site.Pages "Type" "in" "tips"
to get all pages under /tips/
.
Note that in Hugo Type
is an alias of Section
.
Content files under the /tips/
Section also have the Type
of tips
.
However on the Nested Sections Lists you probably need to render only the .RegularPages
residing under the given Nested Section.
To achieve this, I would assign the following layout
parameter to the _index.md
files of the Nested Sections foo
and bar
: layout: subsection
.
Then under /layouts/_default/
i would create a new template called subsection.html
that would be identical to the one in /layouts/_default/list.html
except for the following range
function: range .RegularPages
If you prefer not to have a separate template for subsection
then in layouts/_default/list.html
you can achieve the same by using the following condition:
{{ if eq .Layout "subsection"}}
{{ range .RegularPages }}
<--- HTML --->
{{ end }}
{{ else }}
{{ range where site.Pages "Type" "in" "tips" }}
<--- HTML --->
{{ end }}
{{ end }}
Personally I prefer to work with as few templates as possible in my projects.
Also whichever approach you choose I would recommend that you create a Partial template for your intended HTML output within the above Page lists, so that you can have it in one place and to maintain it easily.
Do read about .Pages
compared to .Site.Pages
.
Also in the above construct .Site
can be replaced with the site
function to access any pages from the global scope within a Hugo project i.e. site.Pages
Also do read about the where
function. There are plenty of examples on that page, that should give you enough info about filtering Page lists according to your needs.