mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Merge commit '77b976dd92b4f66657d83d875aef0c617df492d9'
This commit is contained in:
@@ -22,7 +22,7 @@ The following is a list of page-level variables. Many of these will be defined i
|
||||
: Aliases of this page
|
||||
|
||||
.Ancestors
|
||||
: Get the ancestors of each page, simplify [breadcrumb navigation](/content-management/sections#example-breadcrumb-navigation) implementation complexity
|
||||
: Ancestors of this page.
|
||||
|
||||
.BundleType
|
||||
: The [bundle] type: `leaf`, `branch`, or an empty string if the page is not a bundle.
|
||||
@@ -85,17 +85,14 @@ The following is a list of page-level variables. Many of these will be defined i
|
||||
: Access when creating links to the content. If set, Hugo will use the `linktitle` from the front matter before `title`.
|
||||
|
||||
.Next
|
||||
: Points up to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ with .Next }}{{ .Permalink }}{{ end }}`. Calling `.Next` from the first page returns `nil`.
|
||||
: Points up to the next regular page (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ with .Next }}{{ .Permalink }}{{ end }}`. Calling `.Next` from the first page returns `nil`.
|
||||
|
||||
.NextInSection
|
||||
: Points up to the next [regular page](/variables/site/#site-pages) below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ with .NextInSection }}{{ .Permalink }}{{ end }}`. Calling `.NextInSection` from the first page returns `nil`.
|
||||
: Points up to the next regular page below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ with .NextInSection }}{{ .Permalink }}{{ end }}`. Calling `.NextInSection` from the first page returns `nil`.
|
||||
|
||||
.OutputFormats
|
||||
: Contains all formats, including the current format, for a given page. Can be combined the with [`.Get` function](/functions/get/) to grab a specific format. (See [Output Formats](/templates/output-formats/).)
|
||||
|
||||
.Pages
|
||||
: A collection of associated pages. This value will be `nil` within the context of regular content pages. See [`.Pages`](#pages).
|
||||
|
||||
.Permalink
|
||||
: The Permanent link for this page; see [Permalinks](/content-management/urls/)
|
||||
|
||||
@@ -106,10 +103,10 @@ The following is a list of page-level variables. Many of these will be defined i
|
||||
: The slice of strings that results from splitting .Plain into words, as defined in Go's [strings.Fields](https://pkg.go.dev/strings#Fields).
|
||||
|
||||
.Prev
|
||||
: Points down to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ if .Prev }}{{ .Prev.Permalink }}{{ end }}`. Calling `.Prev` from the last page returns `nil`.
|
||||
: Points down to the previous regular page(sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ if .Prev }}{{ .Prev.Permalink }}{{ end }}`. Calling `.Prev` from the last page returns `nil`.
|
||||
|
||||
.PrevInSection
|
||||
: Points down to the previous [regular page](/variables/site/#site-pages) below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ if .PrevInSection }}{{ .PrevInSection.Permalink }}{{ end }}`. Calling `.PrevInSection` from the last page returns `nil`.
|
||||
: Points down to the previous regular page below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ if .PrevInSection }}{{ .PrevInSection.Permalink }}{{ end }}`. Calling `.PrevInSection` from the last page returns `nil`.
|
||||
|
||||
.PublishDate
|
||||
: The date on which the content was or will be published. By default, this is the front matter `publishDate` value. See [configuring dates] for a description of fallback values and precedence. See also `.Date`, `.ExpiryDate`, and `.Lastmod`.
|
||||
@@ -118,6 +115,9 @@ The following is a list of page-level variables. Many of these will be defined i
|
||||
: Raw markdown content without the front matter. Useful with [remarkjs.com](
|
||||
https://remarkjs.com)
|
||||
|
||||
.RenderShortcodes
|
||||
: See [Render Shortcodes](#rendershortcodes).
|
||||
|
||||
.ReadingTime
|
||||
: The estimated time, in minutes, it takes to read the content.
|
||||
|
||||
@@ -170,6 +170,19 @@ https://remarkjs.com)
|
||||
.WordCount
|
||||
: The number of words in the content.
|
||||
|
||||
## Page collections
|
||||
|
||||
List pages receive the following page collections in [context](/getting-started/glossary/#context):
|
||||
|
||||
.Pages
|
||||
: Regular pages within the current section (not recursive), and section pages for immediate descendant sections (not recursive).
|
||||
|
||||
.RegularPages
|
||||
: Regular pages within the current section (not recursive).
|
||||
|
||||
.RegularPagesRecursive
|
||||
: Regular pages within the current section, and regular pages within all descendant sections.
|
||||
|
||||
## Writable page-scoped variables
|
||||
|
||||
[.Scratch][scratch]
|
||||
@@ -184,15 +197,6 @@ Also see [Sections](/content-management/sections/).
|
||||
|
||||
{{< readfile file="/content/en/readfiles/sectionvars.md" markdown="true" >}}
|
||||
|
||||
## The `.Pages` variable {#pages}
|
||||
|
||||
`.Pages` is an alias to `.Data.Pages`. It is conventional to use the
|
||||
aliased form `.Pages`.
|
||||
|
||||
### `.Pages` compared to `.Site.Pages`
|
||||
|
||||
{{< getcontent path="readfiles/pages-vs-site-pages.md" >}}
|
||||
|
||||
## Page fragments
|
||||
|
||||
{{< new-in "0.111.0" >}}
|
||||
@@ -243,6 +247,34 @@ For this reason, Hugo provides a global `page` function that you can use to acce
|
||||
|
||||
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.
|
||||
|
||||
## The `.RenderShortcodes` method {#rendershortcodes}
|
||||
|
||||
{{< new-in "0.117.0" >}} This renders all the shortcodes in the content, preserving the surrounding markup (e.g. Markdown) as is.
|
||||
|
||||
The common use case this is to composing a page from multiple content files while preserving a global context for table of contents and foot notes.
|
||||
|
||||
This method is most often used in shortcode templates. A simple example of shortcode template including content from another page would look like:
|
||||
|
||||
```go-html-template
|
||||
{{ $p := site.GetPage (.Get 0) }}
|
||||
{{ $p.RenderShortcodes }}
|
||||
```
|
||||
|
||||
In the above it's important to understand and the difference between the two delimiters used when including a shortcode:
|
||||
|
||||
* `{{</* myshortcode */>}}` tells Hugo that the rendered shortcode does not need further processing (e.g. it's HTML).
|
||||
* `{{%/* myshortcode */%}}` tells Hugo that the rendered shortcode needs further processing (e.g. it's Markdown).
|
||||
|
||||
The latter is what you want to use for the include shortcode outlined above:
|
||||
|
||||
```md
|
||||
## Mypage
|
||||
{{%/* include "mypage" */%}}
|
||||
``````
|
||||
|
||||
|
||||
Also see [Use Shortcodes](/content-management/shortcodes/#use-shortcodes).
|
||||
|
||||
## Page-level params
|
||||
|
||||
Any other value defined in the front matter in a content file, including taxonomies, will be made available as part of the `.Params` variable.
|
||||
|
@@ -18,7 +18,7 @@ The following is a list of site-level (aka "global") variables. Many of these va
|
||||
|
||||
All the methods below, e.g. `.Site.RegularPages` can also be reached via the global [`site`](/functions/site/) function, e.g. `site.RegularPages`, which can be handy in partials where the `Page` object isn't easily available.
|
||||
|
||||
## Site variables list
|
||||
## Site variables
|
||||
|
||||
.Site.AllPages
|
||||
: array of all pages, regardless of their translation.
|
||||
@@ -66,7 +66,7 @@ All the methods below, e.g. `.Site.RegularPages` can also be reached via the glo
|
||||
: a string representing the language tag as defined in the site configuration.
|
||||
|
||||
.Site.LanguagePrefix
|
||||
: this can be used to prefix URLs to point to the correct language. It will even work when only one defined language. See also the functions [absLangURL](/functions/abslangurl/) and [relLangURL](/functions/rellangurl).
|
||||
: this can be used to prefix URLs to point to the correct language. It will even work when there is only one defined language. See also the functions [absLangURL](/functions/abslangurl/) and [relLangURL](/functions/rellangurl).
|
||||
|
||||
.Site.Languages
|
||||
: an ordered list (ordered by defined weight) of languages.
|
||||
@@ -78,10 +78,10 @@ All the methods below, e.g. `.Site.RegularPages` can also be reached via the glo
|
||||
: all the menus in the site.
|
||||
|
||||
.Site.Pages
|
||||
: array of all content ordered by Date with the newest first. This array contains only the pages in the current language. See [`.Site.Pages`](#site-pages).
|
||||
: array of all content ordered by Date with the newest first. This array contains only the pages in the current language.
|
||||
|
||||
.Site.RegularPages
|
||||
: a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"`. See [`.Site.Pages`](#site-pages).
|
||||
: a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"`.
|
||||
|
||||
.Site.Sections
|
||||
: top-level directories of the site.
|
||||
@@ -92,7 +92,7 @@ All the methods below, e.g. `.Site.RegularPages` can also be reached via the glo
|
||||
.Site.Title
|
||||
: a string representing the title of the site.
|
||||
|
||||
## The `.Site.Params` variable
|
||||
## Site parameters
|
||||
|
||||
`.Site.Params` is a container holding the values from the `params` section of your site configuration.
|
||||
|
||||
@@ -114,10 +114,4 @@ You can use `.Site.Params` in a [partial template](/templates/partials/) to call
|
||||
<meta name="description" content="{{ if .IsHome }}{{ $.Site.Params.description }}{{ else }}{{ .Description }}{{ end }}" />
|
||||
{{< /code >}}
|
||||
|
||||
## The `.Site.Pages` variable {#site-pages}
|
||||
|
||||
### `.Site.Pages` compared to `.Pages`
|
||||
|
||||
{{< getcontent path="readfiles/pages-vs-site-pages.md" >}}
|
||||
|
||||
[config]: /getting-started/configuration/
|
||||
|
Reference in New Issue
Block a user