Debian Codegraph @

docs/content/en/configuration/params.md

raw
1 ---
2 title: Configure params
3 linkTitle: Params
4 description: Create custom site parameters.
5 categories: []
6 keywords: []
7 ---
8
9 Use the `params` key for custom parameters:
10
11 {{< code-toggle file=hugo >}}
12 baseURL = 'https://example.org/'
13 locale = 'en-US'
14 title = 'Project Documentation'
15 [params]
16 subtitle = 'Reference, Tutorials, and Explanations'
17 [params.contact]
18 email = '[email protected]'
19 phone = '+1 206-555-1212'
20 {{< /code-toggle >}}
21
22 Access the custom parameters from your templates using the [`Params`][] method on a `Site` object:
23
24 ```go-html-template
25 {{ .Site.Params.subtitle }} → Reference, Tutorials, and Explanations
26 {{ .Site.Params.contact.email }} → [email protected]
27 ```
28
29 Key names should use camelCase or snake_case. While TOML, YAML, and JSON allow kebab-case keys, they are not valid [identifiers](g) and cannot be used when [chaining](g) identifiers.
30
31 For example, you can do either of these:
32
33 ```go-html-template
34 {{ .Site.params.camelCase.foo }}
35 {{ .Site.params.snake_case.foo }}
36 ```
37
38 But you cannot do this:
39
40 ```go-html-template
41 {{ .Site.params.kebab-case.foo }}
42 ```
43
44 ## Multilingual projects
45
46 For multilingual projects, create a `params` key under each language:
47
48 {{< code-toggle file=hugo >}}
49 baseURL = 'https://example.org/'
50 defaultContentLanguage = 'en'
51
52 [languages.de]
53 direction = 'ltr'
54 label = 'Deutsch'
55 locale = 'de-DE'
56 title = 'Projekt Dokumentation'
57 weight = 1
58
59 [languages.de.params]
60 subtitle = 'Referenz, Tutorials und Erklärungen'
61
62 [languages.de.params.contact]
63 email = '[email protected]'
64 phone = '+49 30 1234567'
65
66 [languages.en]
67 direction = 'ltr'
68 label = 'English'
69 locale = 'en-US'
70 title = 'Project Documentation'
71 weight = 2
72
73 [languages.en.params]
74 subtitle = 'Reference, Tutorials, and Explanations'
75
76 [languages.en.params.contact]
77 email = '[email protected]'
78 phone = '+1 206-555-1212'
79 {{< /code-toggle >}}
80
81 ## Namespacing
82
83 To prevent naming conflicts, module and theme developers should namespace any custom parameters specific to their module or theme.
84
85 {{< code-toggle file=hugo >}}
86 [params.modules.myModule.colors]
87 background = '#efefef'
88 font = '#222222'
89 {{< /code-toggle >}}
90
91 To access the module/theme settings:
92
93 ```go-html-template
94 {{ $cfg := .Site.Params.module.mymodule }}
95
96 {{ $cfg.colors.background }} → #efefef
97 {{ $cfg.colors.font }} → #222222
98 ```
99
100 [`Params`]: /methods/site/params/