Cond func requires bool type instead of truthy values

It would be more useful if I could do cond (.Params.foo | default .Site.Params.foo) bar baz instead of cond (not (not (.Params.foo | default .Site.Params.foo))) bar baz . This would match the truthy semantics of if statements.

https://github.com/gohugoio/hugo/issues/5792

Also, you can reduce this:

{{ .Params.foo | default .Site.Params.foo }}

To this:

{{ .Param "foo" }}

https://gohugo.io/functions/param/

So your final expression would be:

{{ cond (.Param "foo" | not | not) "bar" "baz" }}
1 Like

I searched GH, but didn’t find that one. Thanks.

Thanks for the .Param and pipe tip! Good to know.

1 Like

Or even shorter, though it might be confusing when looking at your code at some point in the future…

{{ cond (.Param "foo" | not) "baz" "bar" }}

I don’t follow. The condition is opposite by only having one not func.

Right. I reversed “baz” and “bar” in the last example.

Ah, thanks. I was staring right at it. :slight_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.