Beego:我如何在模板中使用If-else条件语句?

huangapple go评论80阅读模式
英文:

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作为模板解析器。

Beego WebIM示例

<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.

Beego WebIM Sample:

&lt;script src=&quot;/static/js/jquery-1.10.1.min.js&quot;&gt;&lt;/script&gt;
{{if .IsLongPolling}}
&lt;script src=&quot;/static/js/longpolling.js&quot;&gt;&lt;/script&gt;
{{else}}
&lt;script src=&quot;/static/js/websocket.js&quot;&gt;&lt;/script&gt;
{{end}}

huangapple
  • 本文由 发表于 2015年7月1日 04:03:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/31147471.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定