mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-02 22:52:51 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -3,40 +3,40 @@ title: Params
|
||||
description: Returns a map of custom parameters as defined in the front matter of the given page.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- functions/collections/IndexFunction
|
||||
- methods/site/Params
|
||||
- methods/page/Param
|
||||
returnType: maps.Params
|
||||
signatures: [PAGE.Params]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: maps.Params
|
||||
signatures: [PAGE.Params]
|
||||
---
|
||||
|
||||
With this front matter:
|
||||
By way of example, consider this front matter:
|
||||
|
||||
{{< code-toggle file=content/news/annual-conference.md >}}
|
||||
{{< code-toggle file=content/annual-conference.md fm=true >}}
|
||||
title = 'Annual conference'
|
||||
date = 2023-10-17T15:11:37-07:00
|
||||
[params]
|
||||
display_related = true
|
||||
key-with-hyphens = 'must use index function'
|
||||
[params.author]
|
||||
email = 'jsmith@example.org'
|
||||
name = 'John Smith'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
The `title` and `date` fields are standard parameters---the other fields are user-defined.
|
||||
The `title` and `date` fields are standard [front matter fields], while the other fields are user-defined.
|
||||
|
||||
Access the custom parameters by [chaining](g) the [identifiers](g):
|
||||
Access the custom fields by [chaining](g) the [identifiers](g) when needed:
|
||||
|
||||
```go-html-template
|
||||
{{ .Params.display_related }} → true
|
||||
{{ .Params.author.email }} → jsmith@example.org
|
||||
{{ .Params.author.name }} → John Smith
|
||||
```
|
||||
|
||||
In the template example above, each of the keys is a valid identifier. For example, none of the keys contains a hyphen. To access a key that is not a valid identifier, use the [`index`] function:
|
||||
|
||||
```go-html-template
|
||||
{{ index .Params "key-with-hyphens" }} → 2023
|
||||
{{ index .Params "key-with-hyphens" }} → must use index function
|
||||
```
|
||||
|
||||
[`index`]: /functions/collections/indexfunction/
|
||||
[front matter fields]: /content-management/front-matter/#fields
|
||||
|
Reference in New Issue
Block a user