mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
This commit is contained in:
65
docs/content/en/methods/page/GetPage.md
Normal file
65
docs/content/en/methods/page/GetPage.md
Normal file
@@ -0,0 +1,65 @@
|
||||
---
|
||||
title: GetPage
|
||||
description: Returns a Page object from the given path.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/site/GetPage
|
||||
returnType: hugolib.pageState
|
||||
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-list.md with a single page template:
|
||||
|
||||
```go-html-template
|
||||
{{ 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 }}
|
||||
```
|
Reference in New Issue
Block a user