1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00
Files
gohugoio-hugo/content/en/functions/param.md
Bjørn Erik Pedersen ef6f101e75 Squashed 'docs/' changes from 2c0125b52..1214f6ffb
1214f6ffb Document cleanDestinationDir configuration setting
27ca65463 Clarify .Page.Param method (#1953)
3fa1792d2 Document the usage of `hardWrap` option for markdown rendering (#1951)
8b5afdfb4 Update theme
207e7f0a0 fix docs for getting remote font
1f7094b9e Correct typo
f9d6445c4 Added missing `/` in URL generator (#1946)
3a22ee7d6 Remove translations
b3b900f3f Update introduction.md
aca440052 rm Forestry - facing end-of-life shortly (#1944)
af0014e14 Update scss-sass.md
1c43bbbc9 Merge branch 'docs/goworkspace'
d034175ca netlify: Hugo 0.109.0
d3a6a5c3f Merge branch 'tempv0.109.0'
e033dbead docs: Regen docs helper JSON
452bf675c resource/page: Add Page.Ancestors
12edd7363 Add some docs for workspaces
8f0fcba6b Add HUGO_PUBLISHDIR to the Node environment
4e66d98ad Update theme
808aee6f6 config: Update to ga v4
1de2bc5a9 config: Update to ga v4
ddb5fd6b0 Merge commit '41bc6f702aa54200530efbf4267e5c823df3028d'
54c54bf76 modules: Adjust watch logic vs workspace use definitions

git-subtree-dir: docs
git-subtree-split: 1214f6ffbf680e853746aaeb6cb097b28c0c556b
2023-01-17 12:51:01 +01:00

1.5 KiB

title, description, signature, categories, keywords, menu, aliases
title description signature categories keywords menu aliases
.Param Returns a page parameter, falling back to a site parameter if present.
.Param KEY
functions
front matter
params
docs
parent
functions

The .Param method on .Page looks for the given KEY in page parameters, and returns the corresponding value. If it cannot find the KEY in page parameters, it looks for the KEY in site parameters. If it cannot find the KEY in either location, the .Param method returns nil.

Site and theme developers commonly set parameters at the site level, allowing content authors to override those parameters at the page level.

For example, to show a table of contents on every page, but allow authors to hide the table of contents as needed:

Configuration

{{< code-toggle file="config" copy=false >}} [params] display_toc = true {{< /code-toggle >}}

Content

{{< code-toggle file="content/about.md" fm=true copy=false >}} title = 'About' date = 2023-01-01 draft = false display_toc = false {{< /code-toggle >}}

Template

{{< code file="layouts/_default/single.html" copy="false" >}} {{ if .Param "display_toc" }} {{ .TableOfContents }} {{ end }} {{< /code >}}

The .Param method returns the value associated with the given KEY, regardless of whether the value is truthy or falsy. If you need to ignore falsy values, use this construct instead:

{{< code file="layouts/_default/single.html" copy="false" >}} {{ or .Params.foo site.Params.foo }} {{< /code >}}