blob: 76b336ae37762dc6a546ff4e9f293d2bbfa64cdd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
---
title: collections.IsSet
description: Reports whether the key exists within the collection.
categories: []
keywords: []
action:
aliases: [isset]
related:
- functions/collections/Dictionary
- functions/collections/Group
- functions/collections/IndexFunction
- functions/collections/Where
- functions/go-template/if
- functions/go-template/with
returnType: bool
signatures: [collections.IsSet COLLECTION KEY]
aliases: [/functions/isset]
---
For example, consider this site configuration:
{{< code-toggle file=hugo >}}
[params]
showHeroImage = false
{{< /code-toggle >}}
It the value of `showHeroImage` is `true`, we can detect that it exists using either `if` or `with`:
```go-html-template
{{ if site.Params.showHeroImage }}
{{ site.Params.showHeroImage }} → true
{{ end }}
{{ with site.Params.showHeroImage }}
{{ . }} → true
{{ end }}
```
But 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:
```go-html-template
{{ if isset site.Params "showheroimage" }}
<p>The showHeroImage parameter is set to {{ site.Params.showHeroImage }}.<p>
{{ end }}
```
{{% note %}}
When using the `isset` function you must reference the key using lower case. See the previous example.
{{% /note %}}
|