blob: 3d8a9a89bb16b01dd8847f5611a6b93c26cd8ce8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
---
title: GetPage
description: Returns a Page object from the given path.
categories: []
keywords: []
action:
related:
- methods/site/GetPage
returnType: page.Page
signatures: [PAGE.GetPage PATH]
aliases: [/functions/getpage]
---
The `GetPage` method is also available on a `Site` object. See [details].
[details]: /methods/site/getpage/
When using the `GetPage` method on the `Page` object, specify a path relative to the current directory or relative to the content directory.
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.
Consider this content structure:
```text
content/
├── works/
│ ├── paintings/
│ │ ├── _index.md
│ │ ├── starry-night.md
│ │ └── the-mona-lisa.md
│ ├── sculptures/
│ │ ├── _index.md
│ │ ├── david.md
│ │ └── the-thinker.md
│ └── _index.md
└── _index.md
```
The examples below depict the result of rendering works/paintings/the-mona-lisa.md:
{{< code file=layouts/works/single.html >}}
{{ with .GetPage "starry-night" }}
{{ .Title }} → Starry Night
{{ end }}
{{ with .GetPage "./starry-night" }}
{{ .Title }} → Starry Night
{{ end }}
{{ with .GetPage "../paintings/starry-night" }}
{{ .Title }} → Starry Night
{{ end }}
{{ with .GetPage "/works/paintings/starry-night" }}
{{ .Title }} → Starry Night
{{ end }}
{{ with .GetPage "../sculptures/david" }}
{{ .Title }} → David
{{ end }}
{{ with .GetPage "/works/sculptures/david" }}
{{ .Title }} → David
{{ end }}
{{< /code >}}
|