我在 Node.js 上使用 Express.js,并用“{{ }}”括号标记参数位置,但默认使用下划线“<% %>”。
app.engine('html', cons.underscore);
// set .html as the default extension
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
在调用渲染方法之前,何时以及如何更改 templateSettings.interpolate 以在模板中包含“{{ }}”括号?
您可以通过 _.templateSetting 对象更改模板设置。信息在 underscore website 。以下是他们用来更改为 Handlebars 样式括号的代码:
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
};
var template = _.template("Hello {{ name }}!");
template({name: "Mustache"});
=> "Hello Mustache!"
这可以放在代码中的任何位置,因为它修改全局下划线对象。
我是一名优秀的程序员,十分优秀!