How to write a conditional in Go Lang like this:
File: view.html
{{ if(var1 =="" && var2 =="" }}
ALL EMPTY
{{else}}
DISPLAY
{{END}}
Templates don't have operators, but they have function eq
, which takes two arguments and returns true if they are equal, and function and
which also takes two arguments and returns true if they're both true. So you could write the first line in your code as:
{{if (and (eq var1 "") (eq var2 ""))}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With