英文:
Beego: How do I use If-else conditions in templates?
问题
如何在beego的模板系统中使用条件语句?
或者只是期望我们使用这个来进行模板化吗?
https://github.com/ipfans/beego-pongo2.v2
在尝试其他方法之前,我想尽力按照Beego的方式来做。我是说...当创建beego的默认模板系统时,肯定考虑了条件渲染,对吗?
顺便问一下,循环怎么处理?
英文:
How do I use conditions in beego's templating system?
Or is it just expected that we use this for templating instead?
https://github.com/ipfans/beego-pongo2.v2
I'd like to try my best first to do this Beego's way before latching something else on here. I mean....surely conditional rendering was thought of when creating beego's stock templating system right?
While we're at it what about looping?
答案1
得分: 3
从Beego模板解析文档中:
Beego使用Go的内置包html/template作为模板解析器。
<script src="/static/js/jquery-1.10.1.min.js"></script>
{{if .IsLongPolling}}
<script src="/static/js/longpolling.js"></script>
{{else}}
<script src="/static/js/websocket.js"></script>
{{end}}
英文:
From Beego Template Parsing docs:
> Beego uses Go’s builtin package html/template as the template parser.
<script src="/static/js/jquery-1.10.1.min.js"></script>
{{if .IsLongPolling}}
<script src="/static/js/longpolling.js"></script>
{{else}}
<script src="/static/js/websocket.js"></script>
{{end}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论