summaryrefslogtreecommitdiffstats
path: root/docs/content/en/methods/site/MainSections.md
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-12-04 15:24:01 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-12-04 15:24:01 +0100
commitd19ed4d4e69f51873135f05a51831d25ecc2071e (patch)
tree74dfd9af2b0f4a6c0933266c50ceaa569d388c71 /docs/content/en/methods/site/MainSections.md
parent9f978d387f8b7cb6bc03fe6b4dd52bb16862a784 (diff)
parent35dec7c96f7ee3eb17dd444f7067f0c776fb56ae (diff)
downloadhugo-d19ed4d4e69f51873135f05a51831d25ecc2071e.tar.gz
hugo-d19ed4d4e69f51873135f05a51831d25ecc2071e.zip
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
Diffstat (limited to 'docs/content/en/methods/site/MainSections.md')
-rw-r--r--docs/content/en/methods/site/MainSections.md55
1 files changed, 55 insertions, 0 deletions
diff --git a/docs/content/en/methods/site/MainSections.md b/docs/content/en/methods/site/MainSections.md
new file mode 100644
index 000000000..251fe1a97
--- /dev/null
+++ b/docs/content/en/methods/site/MainSections.md
@@ -0,0 +1,55 @@
+---
+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.
+categories: []
+keywords: []
+action:
+ related: []
+ returnType: '[]string'
+ signatures: [SITE.MainSections]
+---
+
+Site configuration:
+
+{{< code-toggle file=hugo >}}
+[params]
+mainSections = ['books','films']
+{{< /code-toggle >}}
+
+Template:
+
+```go-html-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:
+
+```text
+content/
+├── books/
+│ ├── book-1.md
+│ └── book-2.md
+├── films/
+│ ├── film-1.md
+│ ├── film-2.md
+│ └── film-3.md
+└── _index.md
+```
+
+Template:
+
+```go-html-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:
+
+```go-html-template
+{{ range where .Site.RegularPages "Section" "in" .Site.MainSections }}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+{{ end }}
+```