我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在模板中添加条件语句

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 ""))}}

近期文章

  • 将C#SHA1代码转换为Golang
  • 在Golang中将表单值分配给struct
  • 如何在Go中以Perl编码的URL安全解码Base64?
  • Golang正则表达式提取2个定界符之间的文本-包括定界符
  • 编译失败:没有这样的文件或目录(但确实存在!)
  • Go中的lambda表达式之类的东西(合并相似的方法)
  • 是否可以使用Go.Regexp匹配除常量字符串以外的所有内容?
  • 如何自动设置GOBIN
  • 在Go中解析XML
  • Golang:可以肯定地说,如果一个结构体实现一个方法,那么它会满足所有定义该方法签名的接口?
  • 为什么RethinkDB非常慢?
  • Go中的OpenCV(或类似库)
  • golang:将毫秒转换为时间
  • 如何在golang中将数组编组为二进制并将数组解组为二进制?
  • 了解Golang中的词法作用域
  • 如何在Golang模板中打印换行? [重复]
  • golang tcp套接字-处理多个消息
  • 使用select的Golang频道不会停止
  • 如何提取Unix时间戳并获取日期
  • 在golang中解析JSON的子部分

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华