List pages of sub-sub-folders

Here is how I am able to modify my sub-sections (nested sections) from within _default/list.html:

{{- if .Sections -}}
{{- range .Sections -}}
{{- range $i, $e := .Data.Pages -}}
<---Layout for parent section---->
{{- end -}}
{{- end -}}
{{- end -}}

The above will be the layout for the list page of the parent (top level) section.

And then to control the layout of sub-sections I simply have the following (right after the above):

{{- range $i, $e := .Data.Pages -}}
<---Layout for sub- section---->
{{- end -}}

And that’'s all there is to it.

I know that @bep and the Hugo Docs say that it is not possible to have a different layout in a nested section, but with a bit of creative thinking it is indeed possible to do this.

And what I posted above I already use in production. So it works like a charm.

Happy holidays everybody! :wink:

6 Likes