Debian Codegraph @

docs/content/en/methods/page/Param.md

raw
1 ---
2 title: Param
3 description: Returns a page parameter with the given key, falling back to a site parameter if present.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: any
9 signatures: [PAGE.Param KEY]
10 aliases: [/functions/param]
11 ---
12
13 The `Param` method on a `Page` object 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`.
14
15 Site and theme developers commonly set parameters at the site level, allowing content authors to override those parameters at the page level.
16
17 For example, to show a table of contents on every page, but allow authors to hide the table of contents as needed:
18
19 Configuration:
20
21 {{< code-toggle file=hugo >}}
22 [params]
23 display_toc = true
24 {{< /code-toggle >}}
25
26 Content:
27
28 {{< code-toggle file=content/example.md fm=true >}}
29 title = 'Example'
30 date = 2023-01-01
31 draft = false
32 [params]
33 display_toc = false
34 {{< /code-toggle >}}
35
36 Template:
37
38 ```go-html-template
39 {{ if .Param "display_toc" }}
40 {{ .TableOfContents }}
41 {{ end }}
42 ```
43
44 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:
45
46 ```go-html-template
47 {{ or .Params.foo site.Params.foo }}
48 ```