Parent
Returns the Page object of the parent section of the given page.
Syntax
PAGE.Parent
Returns
page.Page
A section is a top-level content directory or any content directory containing an _index.md file.
The parent section of a regular page is the current section.
Consider this content structure:
content/
├── auctions/
│ ├── 2023-11/
│ │ ├── _index.md <-- parent: auctions
│ │ ├── auction-1.md
│ │ └── auction-2.md <-- parent: 2023-11
│ ├── 2023-12/
│ │ ├── _index.md
│ │ ├── auction-3.md
│ │ └── auction-4.md
│ ├── _index.md <-- parent: home
│ ├── bidding.md
│ └── payment.md <-- parent: auctions
├── books/
│ ├── _index.md <-- parent: home
│ ├── book-1.md
│ └── book-2.md <-- parent: books
├── films/
│ ├── _index.md <-- parent: home
│ ├── film-1.md
│ └── film-2.md <-- parent: films
└── _index.md <-- parent: nilIn the example above, note the parent section of the home page is nil. Code defensively by verifying existence of the parent section before calling methods on its Page object. To create a link to the parent section page of the current page:
{{ with .Parent }}
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
{{ end }}Last updated:
March 8, 2025
:
content: Replace note shortcode calls with blockquote alerts (c540e6d29)
Improve this page