Cond func requires bool type instead of truthy values

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

Also, you can reduce this:

{{ | default }}

To this:

{{ .Param "foo" }}

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.