How do I escape “{{” and “}}” delimiters in Go templates?

谁说我不能喝 提交于 2019-11-27 19:37:12

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.

{{"{{"}}
{{"}}"}}

produces

{{
}}

A simple workaround would be using

{{`{{Your.Angular.Data}}`}}

In Revel, there is a way to handle it:

In /conf/app.conf, add this line:

template.delimiters="[[ ]]"

It will use [[]] instead of using default {{}}, you can also use:

template.delimiters="{{{ }}}"

So, for revel, it uses {{{ }}}, for angularJS, it uses {{ }}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!