MainSections
Syntax
SITE.MainSections
Returns
[]string
Site configuration:
hugo.
params:
mainSections:
- books
- films
[params]
mainSections = ['books', 'films']
{
"params": {
"mainSections": [
"books",
"films"
]
}
}
Template:
{{ .Site.MainSections }} → [books films]
If params.mainSections
is not defined in the site configuration, this method returns a slice with one element—the top level section with the most pages.
With this content structure, the “films” section has the most pages:
content/
├── books/
│ ├── book-1.md
│ └── book-2.md
├── films/
│ ├── film-1.md
│ ├── film-2.md
│ └── film-3.md
└── _index.md
Template:
{{ .Site.MainSections }} → [films]
When creating a theme, instead of hardcoding section names when listing the most relevant pages on the front page, instruct site authors to set params.mainSections
in their site configuration.
Then your home page template can do something like this:
{{ range where .Site.RegularPages "Section" "in" .Site.MainSections }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}