diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-10-20 09:43:56 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-10-20 09:43:56 +0200 |
commit | e2dd4cd05fa96a08d49b3b198edf0ccf9a94970e (patch) | |
tree | 712334f7e7a657155706f556040575bea9b7757f /docs/content/en/functions/collections/IsSet.md | |
parent | fd381718101a35a5f5f92d5a05b3a0c36ef50db0 (diff) | |
parent | e509cac533600cf4fa8382c9cdab78ddd82db688 (diff) |
Merge commit 'e509cac533600cf4fa8382c9cdab78ddd82db688'
Diffstat (limited to 'docs/content/en/functions/collections/IsSet.md')
-rw-r--r-- | docs/content/en/functions/collections/IsSet.md | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/docs/content/en/functions/collections/IsSet.md b/docs/content/en/functions/collections/IsSet.md new file mode 100644 index 000000000..93fb9f8f6 --- /dev/null +++ b/docs/content/en/functions/collections/IsSet.md @@ -0,0 +1,52 @@ +--- +title: collections.IsSet +linkTitle: isset +description: Reports whether the key exists within the collection. +categories: [functions] +keywords: [] +menu: + docs: + parent: functions +function: + aliases: [isset] + returnType: bool + signatures: [collections.IsSet COLLECTION KEY] +relatedFunctions: + - collections.Dictionary + - collections.Group + - collections.Index + - collections.IsSet + - collections.Where +aliases: [/functions/isset] +--- + +For example, consider this site configuration: + +{{< code-toggle file=hugo copy=false >}} +[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 %}} |