dongsheng4679 2017-03-26 07:52
浏览 9
已采纳

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)

  • 写回答

2条回答 默认 最新

  • dongsou3041 2017-03-26 08:16
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?