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

if语句转到模板中的多个条件

how can I have multiple conditions in an if statement inside a template?

I tried this code:

{{ if .condition1 && .condition2 }}
    <!-- SHOW SOMETHING -->
{{ end }}

But it doesn't work. (in fact it panics)

You need to use function and, like:

{{ if and .condition1 .condition2 }}
<!-- SHOW SOMETHING -->
{{ end }}

Here's an working example: https://play.golang.org/p/g_itE5ggCM

You can also have a try with my go project the fet template engineer, compile your "smarty like" code into html/template code, support expressions, improve your writing experience.

近期文章

  • 去旅游爬虫运动麻烦
  • 为什么不使用%v打印int和字符串
  • 与C ++ / C相比的Golang内存布局
  • Go的修订历史背后的故事是什么?
  • 如何在golang中将bool转换为int8 [重复]
  • 如何在Windows上隐藏Go程序的控制台窗口[重复]
  • 在函数内部还是外部定义结构的含义?
  • 是否可以同时进行测试运行单元测试?
  • 如何使CMake与go编程语言一起使用?
  • Go中path和path.filepath包之间有什么区别
  • 指针和struct中的值有什么区别?
  • 解组后访问嵌套JSON数组的Golang问题
  • 有没有在Go中设计信号或事件API的首选方法?
  • 检查进程是否存在
  • 如何在 Golang 中解析 JSON 数组?
  • 如何使用mgo和Go查询日期范围的MongoDB?
  • http.Get返回协议不可用错误[关闭]
  • 您如何在Go中设置和清除一点?
  • Golang中的严格json解析器
  • 在Go中,未命名的参数是否有用?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华