ds9567 2014-08-05 03:56
浏览 263
已采纳

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

I'd like to execute template with noescape and no quotes, but noescape is not supported now.

Any suggestion or do I have to use another template engine? Thank you!

Code here: http://play.golang.org/p/R-Ib5H9bXx

  • 写回答

1条回答 默认 最新

  • douweibeng5219 2014-08-05 05:41
    关注

    You are encouraged to store safe Javascript in the type 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() } 'foo'", which is both a valid Expression and a valid Program with a very different meaning.

    So, the only change you need to do to your code is:

    type Var struct {
        Name  template.JS
        Value template.JS
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料