Is it possible to use an OR / AND conditional rather than IF...ELSE?

So I’m trying to reduce the number of IF/ELSE statements. Is there a way I can incorporate an OR conditional inside an IF statement to check if either param A or param B is set?

This obviously doesn’t work, but kinda what I am after

---
media:
    image:
    svg: this is set
---
{{ with .media }}
  {{if ( or ( .image ) ( .svg )) }}
     <div class="media">
        {{.image}}
        {{.svg}}
     </div>
  {{end}}
{{end}}

Ideally I’m looking for something that’s more readable without having multiple IF statements just to check if some parameters with the same context are there.

I’ve tried using a variation of not (eq .image "") | or (eq .svg "") and isset but I keep getting an error of wrong number of args for safeHTML: want 1 got 0.

Is it possible to use an OR conditional for this purpose?

{{ if or ( .image ) ( .svg ) }}
{{ if and ( .image ) ( .svg ) }}
{{ if or ( .image ) (not .svg ) }}
2 Likes

I hope this is a typo. To access user variables, you must use .Params. {{ with .Params.media }}

Thanks @Mikhail. Turns out I had a set of old parameters that I forgot to change to the newer cleaner version - which was causing the errors. Frustrating lesson learned. But your method works, thanks!

Also in this particular case it wasn’t a typo. My media parameter is within a range statement.