gpt4 book ai didi

node.js - underscore.js 与 consolidate.js : how to change templateSettings?

转载 作者:太空宇宙 更新时间:2023-11-03 23:42:56 34 4
gpt4 key购买 nike

我在 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!"

这可以放在代码中的任何位置,因为它修改全局下划线对象。

关于node.js - underscore.js 与 consolidate.js : how to change templateSettings?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19659344/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com