mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -3,34 +3,33 @@ title: Page
|
||||
description: Returns the Page object of the given page.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: page.Page
|
||||
signatures: [PAGE.Page]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: page.Page
|
||||
signatures: [PAGE.Page]
|
||||
---
|
||||
|
||||
This is a convenience method, useful within partial templates that are called from both [shortcodes](g) and page templates.
|
||||
|
||||
{{< code file=layouts/shortcodes/foo.html >}}
|
||||
```go-html-template {file="layouts/shortcodes/foo.html"}
|
||||
{{ partial "my-partial.html" . }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
When the shortcode calls the partial, it passes the current [context](g) (the dot). The context includes identifiers such as `Page`, `Params`, `Inner`, and `Name`.
|
||||
|
||||
{{< code file=layouts/_default/single.html >}}
|
||||
```go-html-template {file="layouts/_default/single.html"}
|
||||
{{ partial "my-partial.html" . }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
When the page template calls the partial, it also passes the current context (the dot). But in this case, the dot _is_ the `Page` object.
|
||||
|
||||
{{< code file=layouts/partials/my-partial.html >}}
|
||||
```go-html-template {file="layouts/partials/my-partial.html"}
|
||||
The page title is: {{ .Page.Title }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
To handle both scenarios, the partial template must be able to access the `Page` object with `Page.Page`.
|
||||
|
||||
{{% note %}}
|
||||
And yes, that means you can do `.Page.Page.Page.Page.Title` too.
|
||||
|
||||
But don't.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> And yes, that means you can do `.Page.Page.Page.Page.Title` too.
|
||||
>
|
||||
> But don't.
|
||||
|
Reference in New Issue
Block a user