Merge commit '87de22d7464e239c775fbd48ebce1665d5b1e80d'

This commit is contained in:
Bjørn Erik Pedersen
2023-07-29 11:17:28 +02:00
177 changed files with 1623 additions and 1556 deletions

View File

@@ -1,14 +1,15 @@
---
title: Variables and Params
linktitle: Variables Overview
title: Variables and parameters
linkTitle: Overview
description: Page-, file-, taxonomy-, and site-level variables and parameters available in templates.
categories: [variables and params]
categories: [variables and parameters]
keywords: [variables,params,values,globals]
menu:
docs:
identifier: variables-overview
parent: variables
weight: 1
weight: 01
weight: 1
aliases: [/templates/variables/]
---

View File

@@ -1,7 +1,7 @@
---
title: File Variables
title: File variables
description: "Use File variables to access file-related values for each page that is backed by a file."
categories: [variables and params]
categories: [variables and parameters]
keywords: [files]
menu:
docs:

View File

@@ -1,8 +1,8 @@
---
title: Git Info Variables
linktitle: Git Variables
title: Git variables
linkTitle: Git variables
description: Get the last Git revision information for every content file.
categories: [variables and params]
categories: [variables and parameters]
keywords: [git]
menu:
docs:
@@ -16,13 +16,13 @@ aliases: [/extras/gitinfo/]
Hugo's Git integrations should be fairly performant but *can* increase your build time. This will depend on the size of your Git history.
{{% /note %}}
## `.GitInfo` Prerequisites
## `.GitInfo` prerequisites
1. The Hugo site must be in a Git-enabled directory.
2. The Git executable must be installed and in your system `PATH`.
3. The `.GitInfo` feature must be enabled in your Hugo project by passing `--enableGitInfo` flag on the command line or by setting `enableGitInfo` to `true` in your [site's configuration file][configuration].
## The `.GitInfo` Object
## The `.GitInfo` object
The `GitInfo` object contains the following fields:

View File

@@ -1,7 +1,7 @@
---
title: Menu Variables
title: Menu variables
description: Use these variables and methods in your menu templates.
categories: [variables and params]
categories: [variables and parameters]
keywords: [menus]
menu:
docs:

View File

@@ -1,7 +1,7 @@
---
title: Page Variables
title: Page variables
description: Page-level variables are defined in a content file's front matter, derived from the content's file location, or extracted from the content body itself.
categories: [variables and params]
categories: [variables and parameters]
keywords: [pages]
menu:
docs:
@@ -13,7 +13,7 @@ toc: true
The following is a list of page-level variables. Many of these will be defined in the front matter, derived from file location, or extracted from the content itself.
## Page Variables
## Page variables
.AlternativeOutputFormats
: contains all alternative formats for a given page; this variable is especially useful `link rel` list in your site's `<head>`. (See [Output Formats](/templates/output-formats/).)
@@ -176,7 +176,7 @@ https://remarkjs.com)
.WordCount
: the number of words in the content.
## Writable Page-scoped Variables
## Writable page-scoped variables
[.Scratch][scratch]
: returns a Scratch to store and manipulate data. In contrast to the [`.Store`][store] method, this scratch is reset on server rebuilds.
@@ -184,13 +184,13 @@ https://remarkjs.com)
[.Store][store]
: returns a Scratch to store and manipulate data. In contrast to the [`.Scratch`][scratch] method, this scratch is not reset on server rebuilds.
## Section Variables and Methods
## Section variables and methods
Also see [Sections](/content-management/sections/).
{{< readfile file="/content/en/readfiles/sectionvars.md" markdown="true" >}}
## The `.Pages` Variable {#pages}
## The `.Pages` variable {#pages}
`.Pages` is an alias to `.Data.Pages`. It is conventional to use the
aliased form `.Pages`.
@@ -199,7 +199,7 @@ aliased form `.Pages`.
{{< getcontent path="readfiles/pages-vs-site-pages.md" >}}
## Page Fragments
## Page fragments
{{< new-in "0.111.0" >}}
@@ -249,7 +249,7 @@ 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.
## Page-level Params
## 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.
@@ -290,9 +290,9 @@ This template would render as follows:
See [Archetypes](/content-management/archetypes/) for consistency of `Params` across pieces of content.
{{% /note %}}
### The `.Param` Method
### The `.Param` method
In Hugo, you can declare params in individual pages and globally for your entire website. A common use case is to have a general value for the site param and a more specific value for some of the pages (i.e., a header image):
In Hugo, you can declare parameters in individual pages and globally for your entire website. A common use case is to have a general value for the site parameter and a more specific value for some of the pages (i.e., a header image):
```go-html-template
{{ $.Param "header_image" }}
@@ -300,7 +300,7 @@ In Hugo, you can declare params in individual pages and globally for your entire
The `.Param` method provides a way to resolve a single value according to it's definition in a page parameter (i.e. in the content's front matter) or a site parameter (i.e., in your site configuration).
### Access Nested Fields in Front Matter
### Access nested fields in front matter
When front matter contains nested fields like the following:

View File

@@ -1,7 +1,7 @@
---
title: Pages Methods
title: Pages methods
description: Pages is the core page collection in Hugo and has many useful methods.
categories: [variables and params]
categories: [variables and parameters]
keywords: [pages]
menu:
docs:

View File

@@ -1,7 +1,7 @@
---
title: Shortcode Variables
title: Shortcode variables
description: Shortcodes can access page variables and also have their own specific built-in variables.
categories: [variables and params]
categories: [variables and parameters]
keywords: [shortcodes]
menu:
docs:
@@ -25,7 +25,7 @@ weight: 20
: provides access to the parent shortcode context in nested shortcodes. This can be very useful for inheritance of common shortcode parameters from the root.
.Position
: Contains [filename and position](https://godoc.org/github.com/gohugoio/hugo/common/text#Position) for the shortcode in a page. Note that this can be relatively expensive to calculate, and is meant for error reporting. See [Error Handling in Shortcodes](/templates/shortcode-templates/#error-handling-in-shortcodes).
: Contains [file name and position](https://godoc.org/github.com/gohugoio/hugo/common/text#Position) for the shortcode in a page. Note that this can be relatively expensive to calculate, and is meant for error reporting. See [Error Handling in Shortcodes](/templates/shortcode-templates/#error-handling-in-shortcodes).
.IsNamedParams
: boolean that returns `true` when the shortcode in question uses [named rather than positional parameters][shortcodes]

View File

@@ -1,7 +1,7 @@
---
title: Site Variables
title: Site variables
description: Many, but not all, site-wide variables are defined in your site's configuration. However, Hugo provides a number of built-in variables for convenient access to global values in your templates.
categories: [variables and params]
categories: [variables and parameters]
keywords: [global,site]
menu:
docs:
@@ -14,11 +14,11 @@ toc: true
The following is a list of site-level (aka "global") variables. Many of these variables are defined in your site's [configuration file][config], whereas others are built into Hugo's core for convenient usage in your templates.
## Get the Site object from a partial
## Get the site object from a partial
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 list
.Site.AllPages
: array of all pages, regardless of their translation.
@@ -42,7 +42,7 @@ All the methods below, e.g. `.Site.RegularPages` can also be reached via the glo
: a string representing your tracking code for Google Analytics as defined in the site configuration.
.Site.Home
: reference to the homepage's [page object](https://gohugo.io/variables/page/)
: reference to the homepage's [page object](/variables/page/)
.Site.IsMultiLingual
: whether there are more than one language in this site. See [Multilingual](/content-management/multilingual/) for more information.
@@ -92,13 +92,13 @@ 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
## The `.Site.Params` variable
`.Site.Params` is a container holding the values from the `params` section of your site configuration.
### Example: `.Site.Params`
The following `config.[yaml|toml|json]` defines a site-wide param for `description`:
The following `config.[yaml|toml|json]` defines a site-wide parameter for `description`:
{{< code-toggle file="hugo" >}}
baseURL = "https://yoursite.example.com/"
@@ -114,7 +114,7 @@ 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}
## The `.Site.Pages` variable {#site-pages}
### `.Site.Pages` compared to `.Pages`

View File

@@ -1,8 +1,7 @@
---
title: Sitemap Variables
linktitle: Sitemap Variables
title: Sitemap variables
description:
categories: [variables and params]
categories: [variables and parameters]
keywords: [sitemap]
menu:
docs:
@@ -20,6 +19,6 @@ A sitemap is a `Page` and therefore has all the [page variables][pagevars] avail
: the priority of the page
.Sitemap.Filename
: the sitemap filename
: the sitemap file name
[pagevars]: /variables/page/

View File

@@ -1,7 +1,7 @@
---
title: Taxonomy Variables
title: Taxonomy variables
description: Hugo's taxonomy system exposes variables to taxonomy and term templates.
categories: [variables and params]
categories: [variables and parameters]
keywords: [taxonomy,term]
menu:
docs: