Debian Codegraph @

docs/content/en/methods/page/Parent.md

raw
1 ---
2 title: Parent
3 description: Returns the Page object of the parent section of the given page.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Page
9 signatures: [PAGE.Parent]
10 ---
11
12 {{% glossary-term section %}}
13
14 > [!NOTE]
15 > The parent section of a regular page is the [current section][].
16
17 Consider this content structure:
18
19 ```tree
20 content/
21 ├── auctions/
22 │ ├── 2023-11/
23 │ │ ├── _index.md <-- parent: auctions
24 │ │ ├── auction-1.md
25 │ │ └── auction-2.md <-- parent: 2023-11
26 │ ├── 2023-12/
27 │ │ ├── _index.md
28 │ │ ├── auction-3.md
29 │ │ └── auction-4.md
30 │ ├── _index.md <-- parent: home
31 │ ├── bidding.md
32 │ └── payment.md <-- parent: auctions
33 ├── books/
34 │ ├── _index.md <-- parent: home
35 │ ├── book-1.md
36 │ └── book-2.md <-- parent: books
37 ├── films/
38 │ ├── _index.md <-- parent: home
39 │ ├── film-1.md
40 │ └── film-2.md <-- parent: films
41 └── _index.md <-- parent: nil
42 ```
43
44 In 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:
45
46 ```go-html-template
47 {{ with .Parent }}
48 <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
49 {{ end }}
50 ```
51
52 [current section]: /methods/page/currentsection/