Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add conditional sentences in template

Tags:

templates

go

How to write a conditional in Go Lang like this:

File: view.html

{{ if(var1 =="" && var2 =="" }}
ALL EMPTY
{{else}}
DISPLAY 
{{END}}
like image 504
Nguyễn Dũng Avatar asked Sep 06 '25 22:09

Nguyễn Dũng


1 Answers

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 ""))}}
like image 154
jussius Avatar answered Sep 08 '25 20:09

jussius