GetPage.md - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
GetPage.md (1658B)
---
1 ---
2 title: GetPage
3 description: Returns a Page object from the given path.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Page
9 signatures: [PAGE.GetPage PATH]
10 aliases: [/functions/getpage]
11 ---
12
13 The `GetPage` method is also available on a `Site` object. See [details].
14
15 [details]: /methods/site/getpage/
16
17 When using the `GetPage` method on the `Page` object, specify a path relative to the current directory or relative to the `content` directory.
18
19 If Hugo cannot resolve the path to a page, the method returns nil. If the path is ambiguous, Hugo throws an error and fails the build.
20
21 Consider this content structure:
22
23 ```text
24 content/
25 ├── works/
26 │ ├── paintings/
27 │ │ ├── _index.md
28 │ │ ├── starry-night.md
29 │ │ └── the-mona-lisa.md
30 │ ├── sculptures/
31 │ │ ├── _index.md
32 │ │ ├── david.md
33 │ │ └── the-thinker.md
34 │ └── _index.md
35 └── _index.md
36 ```
37
38 The examples below depict the result of rendering `works/paintings/the-mona-lisa.md`:
39
40 ```go-html-template {file="layouts/works/page.html"}
41 {{ with .GetPage "starry-night" }}
42 {{ .Title }} → Starry Night
43 {{ end }}
44
45 {{ with .GetPage "./starry-night" }}
46 {{ .Title }} → Starry Night
47 {{ end }}
48
49 {{ with .GetPage "../paintings/starry-night" }}
50 {{ .Title }} → Starry Night
51 {{ end }}
52
53 {{ with .GetPage "/works/paintings/starry-night" }}
54 {{ .Title }} → Starry Night
55 {{ end }}
56
57 {{ with .GetPage "../sculptures/david" }}
58 {{ .Title }} → David
59 {{ end }}
60
61 {{ with .GetPage "/works/sculptures/david" }}
62 {{ .Title }} → David
63 {{ end }}
64 ```