mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
Add a paragraph about the new page template function
This commit is contained in:
@@ -236,7 +236,21 @@ Also see the [Go Doc](https://pkg.go.dev/github.com/gohugoio/hugo@v0.111.0/marku
|
||||
`.Fragments` are safe to call from render hooks, even on the page you're on (`.Page.Fragments`). For shortcodes we recommend that all `.Fragments` usage is nested inside the `{{</**/>}}` shortcode delimiter (`{{%/**/%}}` takes part in the ToC creation so it's easy to end up in a situation where you bite yourself in the tail).
|
||||
|
||||
|
||||
## The global page function
|
||||
|
||||
{{< new-in "0.111.1" >}}
|
||||
|
||||
Hugo almost always passes a `Page` as the data context into the top level template (e.g. `single.html`) (the one exception is the multihost sitemap template). This means that you can access the current page with the `.` variable in the template.
|
||||
|
||||
But when you're deeply nested inside `.Render`, partial etc., accessing that `Page` object isn't always practical or possible.
|
||||
|
||||
For this reason, Hugo provides a global `page` function that you can use to access the current page from anywhere in any template.
|
||||
|
||||
```go-html-template
|
||||
{{ page.Title }}
|
||||
```
|
||||
|
||||
There are one caveat with this, and this isn't new, but it's worth mentioning here: There are situations in Hugo where you may see a cached value, e.g. when using `partialCached` or in a shortcode.
|
||||
|
||||
## Page-level Params
|
||||
|
||||
|
||||
Reference in New Issue
Block a user