在(Wordpress打包)Underscore 1.6中使用自定义标签,我试图做这样的事情:
{| if (1 < 2) print('success') |}
这是Underscore自定义配置:
_.templateSettings = {
evaluate : /\{\|(.+?)\|}/g,
};
每当我使用<
或>
运算符时,我都会得到以下结果:
Uncaught SyntaxError: Unexpected token ;
但如果我使用==
一切都没问题。为什么?
对我不知道的运营商有一些限制吗?
答案 0 :(得分:0)
由于我的模板是一个实际的HTML元素,因此使用innterHTML检索模板代码会返回一个带有html实体编码的字符串。解决方案很简单:
var template = _.template(_.unescape(this.el.innterHTML))
。