go - 在golang中执行不带引号的模板

标签 go template-engine

我想用 noescape 执行模板并且没有引号,但是现在不支持 noescape

有什么建议或者我必须使用另一个模板引擎吗?谢谢!

代码在这里:http://play.golang.org/p/R-Ib5H9bXx

最佳答案

我们鼓励您将安全的 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/

相关文章:

testing - 测试 Go 时如何跨包共享设置和拆卸方法?

lua - 如何在 Lightroom Web 引擎 Lua 模板中显示 "image X of Y"?

javascript - HTML 模板引擎和 Liquid

go - "go get"如何知道远程 repo 要使用什么版本控制系统?

Golang,带有值接收器的函数的函数指针,在第二次调用时不会使用更改的接收器调用该函数

go - 云 Spanner IAM 权限被拒绝

GO:我正在尝试猜测我的号码,但我的程序无法正确解释数字

java - 将 Freemarker 转换为 PDF

java - 非servlet JSP

php - 使用 include 或 eval 自定义流包装器?