hugo/docs/content/en/functions/collections/IsSet.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.2 KiB

title description categories keywords action aliases
collections.IsSet Reports whether the key exists within the collection.
aliases related returnType signatures
isset
functions/go-template/if
functions/go-template/with
bool
collections.IsSet COLLECTION KEY
/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:

{{ 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:

{{ 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 %}}