Handlebars.js的双花括号和三花括号之间有什么区别

时间:2017-11-08 11:30:32

标签: handlebars.js

例如,您可以看到{{{body}}},在模板中,您可以执行{{data.page.hero.text}}

之类的操作

我们应该注意哪些重大差异?

2 个答案:

答案 0 :(得分:8)

Handlebars HTML-escapes {{expression}}返回的值。如果您不希望Handlebars转义值,请使用" triple-stash",{{{。

参考:http://handlebarsjs.com/#html-escaping

答案 1 :(得分:0)

Depending on your use case and logic, you may add an option "noEscape" set to true when compiling the template if you want to use {{ }} when {{{ }}} are required to successfully replace the templates. For example: replacing with JSON values.

From the documentation:

var template = Handlebars.compile('{{foo}}', { noEscape: true });

noEscape: Set to true to not HTML escape any content.