Debian Codegraph @

docs/content/en/functions/collections/IsSet.md

raw
1 ---
2 title: collections.IsSet
3 description: Reports whether a specific key or index exists in the given map or slice.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [isset]
9 returnType: bool
10 signatures: [collections.IsSet MAP|SLICE KEY|INDEX]
11 aliases: [/functions/isset]
12 ---
13
14 For example, consider this project configuration:
15
16 {{< code-toggle file=hugo >}}
17 [params]
18 showHeroImage = false
19 {{< /code-toggle >}}
20
21 If the value of `showHeroImage` is `true`, we can detect that it exists using either `if` or `with`:
22
23 ```go-html-template
24 {{ if site.Params.showHeroImage }}
25 {{ site.Params.showHeroImage }} → true
26 {{ end }}
27
28 {{ with site.Params.showHeroImage }}
29 {{ . }} → true
30 {{ end }}
31 ```
32
33 However, if the value of `showHeroImage` is `false`, we can't use either `if` or `with` to detect its existence. In this case, you must use the `isset` function:
34
35 ```go-html-template
36 {{ if isset site.Params "showheroimage" }}
37 <p>The showHeroImage parameter is set to {{ site.Params.showHeroImage }}.<p>
38 {{ end }}
39 ```
40
41 > [!NOTE]
42 > When using the `isset` function you must reference the key using lower case. See the previous example.