如何在Go模板中转义“{{”和“}}”分隔符? [英] How do I escape “{{” and “}}” delimiters in Go templates?

查看:802
本文介绍了如何在Go模板中转义“{{”和“}}”分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆