I have the following construct:
{{ $value := site.Data.foldername }}
{{ if (and (isset $value "config") (isset $value.config "plugins") (isset $value.config.plugins "scss")) }}
...
{{ end }}
$value
exists, but has no section config and so $value.config.plugins
and $value.config.plugins.scss
do not exist.
(for example there is a folder data/foldername/something.toml
with some toml config data in it)
I would expect the if-construct to bail out silently on the first and parameter (does $value have a section 'config"? nope.)
But it does not, it fails with the famed warning:
WARNING: calling IsSet with unsupported type "invalid" (<nil>) will always return false.
I am very sure that the if-line is throwing this warning (debugged it line by line).
If I change the line into three separate if lines the warning disappears.
{{ if isset $value "config" }}
{{ if isset $value.config "plugins" }}
{{ if isset $value.config.plugins "scss" }}
...
{{ end }}
{{ end }}
{{ end }}
Shouldn’t the first if being false lead to the whole loop be ignored without an error?
Hmm… it seems the issue is not with the if
, but in the and
and that logically needs to check at least two parameters. Back to the drawing board.
It could short curcuit though: if the first value is false
the whole expression must be false.
bep
4
This is going to be fixed soonish…
1 Like
system
Closed
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.