如何在Go模板中转义“{{”和“}}”分隔符? [英] How do I escape “{{” and “}}” delimiters in Go templates?
问题描述
我使用AngularJS作为前端JS库,使用Revel框架中的Go模板来在后端生成标记。
Go和Angular在其模板中使用 {{
和}}
分隔符。如何在Go中将它们转义并传递给AngularJS?
Delims
:$ b
func(t * Template)Delims(左,右字符串)* Template
根据邮件列表,这可能是最好的选择。争论的是,如果你逃脱它,你的模板将难以阅读,所以无论如何改变分隔符可能会更好,而不是试图绕开它。
I’m using AngularJS as the front-end JS library, with Go templates within Revel framework to to generate the markup on the back-end.
But both Go and Angular use {{
and }}
for delimiters in their templates. How can I escape them in Go to pass them to AngularJS?
I don't know how to escape it, but you could choose a different delimiter instead using Delims
:
func (t *Template) Delims(left, right string) *Template
According to the mailing list, this is probably the best option. The argument was that if you escape it, your templates will be hard to read, so it would probably be better anyway to change the delimiter instead of trying to hack around it.
这篇关于如何在Go模板中转义“{{”和“}}”分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!