问题描述
我使用 AngularJS 作为前端 JS 库,使用 Revel 框架内的 Go 模板在后端生成标记.
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.
但是 Go 和 Angular 都使用 {{
和 }}
作为模板中的分隔符.如何在 Go 中转义它们以将它们传递给 AngularJS?
But both Go and Angular use {{
and }}
for delimiters in their templates. How can I escape them in Go to pass them to AngularJS?
推荐答案
我不知道如何转义它,但您可以使用 Delims
:
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 模板中转义“{{"和“}}"分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!