I want to use the cond
function to assign a value to a variable. The condition for the assignment depends on whether a particular param variable exists or not.
Could someone help me with this?
{{ $variable2 := (cond ($.Param "variable1") "true value" "false value") }}
This fails because $.Param "variable1"
isn’t a conditional expression. Is there a way to turn it into an inline conditional expression.
I’ve also tried using if
and nesting the conditionals but for some reason, I can’t overwrite the values of the variable.
{{ $variable2 := "some value" /*Initializing necessary for Hugo*/ }}
{{ if ($.Params "variable1") }}
{{ $variable2 := "true value" }}
{{ else }}
{{ $variable2 := "false value" }}
{{ end }}
Why does this simple code snippet fail? Please help me with both of these snippets.