mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
---
|
||||
title: MainSections
|
||||
description: Returns a slice of the main section names as defined in the site configuration, falling back to the top level section with the most pages.
|
||||
description: Returns a slice of the main section names as defined in the site configuration, falling back to the top-level section with the most pages.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: '[]string'
|
||||
signatures: [SITE.MainSections]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: '[]string'
|
||||
signatures: [SITE.MainSections]
|
||||
---
|
||||
|
||||
Site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[params]
|
||||
mainSections = ['books','films']
|
||||
{{< /code-toggle >}}
|
||||
|
||||
@@ -22,7 +21,7 @@ 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.
|
||||
If `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:
|
||||
|
||||
@@ -44,7 +43,7 @@ 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.
|
||||
When creating a theme, instead of hardcoding section names when listing the most relevant pages on the front page, instruct site authors to set `mainSections` in their site configuration.
|
||||
|
||||
Then your home template can do something like this:
|
||||
|
||||
|
Reference in New Issue
Block a user