If isset conditional logic

I noticed a strange - to me - behaviour in the logic of conditional statements.
Let’s start from the docs regarding the rules of conditionals:

Go Templates treat the following values as false:
false; 0; any array, slice, map, or string of length zero

Now, I created in my config.toml this variable


and then in index.html:

{{ if isset .Site.Params "foo" }}
{{ end }}

Well, the problem is that FOO is displayed although it’s set on false. If I remove the variable in the config.toml file, it correctly doesn’t display FOO.

Am I missing something?

Hello @tubia,

the isset template function works as expected. isset just checks if you have defined foo in your config file. It’s doesn’t evaluate the content of foo. In this case true will be returned (independent from the value). If you remove foo then isset will return false because foo can’t be found.

If you want evaluate foo in the if-statement you need to write {{ if .Site.Params.foo }}.


Helpful, thanks.