| 1 |
--- |
| 2 |
title: Sections |
| 3 |
description: Returns a collection of section pages, one for each immediate descendant section of the given page. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: page.Pages |
| 9 |
signatures: [PAGE.Sections] |
| 10 |
--- |
| 11 |
|
| 12 |
The `Sections` method on a `Page` object is available to these [page kinds](g): `home`, `section`, and `taxonomy`. The templates for these page kinds receive a page [collection](g) in [context](g), in the [default sort order](g). |
| 13 |
|
| 14 |
With this content structure: |
| 15 |
|
| 16 |
```tree |
| 17 |
content/ |
| 18 |
├── auctions/ |
| 19 |
│ ├── 2023-11/ |
| 20 |
│ │ ├── _index.md <-- front matter: weight = 202311 |
| 21 |
│ │ ├── auction-1.md |
| 22 |
│ │ └── auction-2.md |
| 23 |
│ ├── 2023-12/ |
| 24 |
│ │ ├── _index.md <-- front matter: weight = 202312 |
| 25 |
│ │ ├── auction-3.md |
| 26 |
│ │ └── auction-4.md |
| 27 |
│ ├── _index.md <-- front matter: weight = 30 |
| 28 |
│ ├── bidding.md |
| 29 |
│ └── payment.md |
| 30 |
├── books/ |
| 31 |
│ ├── _index.md <-- front matter: weight = 20 |
| 32 |
│ ├── book-1.md |
| 33 |
│ └── book-2.md |
| 34 |
├── films/ |
| 35 |
│ ├── _index.md <-- front matter: weight = 10 |
| 36 |
│ ├── film-1.md |
| 37 |
│ └── film-2.md |
| 38 |
└── _index.md |
| 39 |
``` |
| 40 |
|
| 41 |
And this template: |
| 42 |
|
| 43 |
```go-html-template |
| 44 |
{{ range .Sections.ByWeight }} |
| 45 |
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2> |
| 46 |
{{ end }} |
| 47 |
``` |
| 48 |
|
| 49 |
On the home page, Hugo renders: |
| 50 |
|
| 51 |
```html |
| 52 |
<h2><a href="/films/">Films</a></h2> |
| 53 |
<h2><a href="/books/">Books</a></h2> |
| 54 |
<h2><a href="/auctions/">Auctions</a></h2> |
| 55 |
``` |
| 56 |
|
| 57 |
On the auctions page, Hugo renders: |
| 58 |
|
| 59 |
```html |
| 60 |
<h2><a href="/auctions/2023-11/">Auctions in November 2023</a></h2> |
| 61 |
<h2><a href="/auctions/2023-12/">Auctions in December 2023</a></h2> |
| 62 |
``` |