我想用 noescape
执行模板并且没有引号,但是现在不支持 noescape
。
有什么建议或者我必须使用另一个模板引擎吗?谢谢!
最佳答案
我们鼓励您将安全的 Javascript 存储在 template.JS
类型中:
type JS string
JS encapsulates a known safe EcmaScript5 Expression, for example,
(x + y * z())
. Template authors are responsible for ensuring that typed expressions do not break the intended precedence and that there is no statement/expression ambiguity as when passing an expression like "{ foo: bar() }\n'foo'", which is both a valid Expression and a valid Program with a very different meaning.
因此,您需要对代码做的唯一更改是:
type Var struct {
Name template.JS
Value template.JS
}
关于go - 在golang中执行不带引号的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25130946/