Node.js 如何使用cons.下划线编译动态html?

Node.js 如何使用cons.下划线编译动态html?,node.js,underscore.js,Node.js,Underscore.js,我已经将静态html转换为字符串并通过电子邮件发送。现在,我们希望将动态值传递给html,并将其转换为字符串并发送电子邮件。我使用cons.下划线作为呈现html页面的视图引擎 不要使用readFileSync!它会锁定你的程序 如果需要将动态变量传递到模板呈现中,则需要在express服务器中使用.render 也许您需要安装扩展: npm install underscore --save npm install consolidate --save 为此,请在express中设置模板引擎

我已经将静态html转换为字符串并通过电子邮件发送。现在,我们希望将动态值传递给html,并将其转换为字符串并发送电子邮件。我使用cons.下划线作为呈现html页面的视图引擎

不要使用readFileSync!它会锁定你的程序

如果需要将动态变量传递到模板呈现中,则需要在express服务器中使用.render

也许您需要安装扩展:

npm install underscore --save
npm install consolidate --save
为此,请在express中设置模板引擎:

app.set('view engine', 'html');
app.engine('html', require('consolidate').underscore);
然后在您的侦听器上获得如下页面:

var options = { email : 'test@op.com'};
res.render('index', options);

通过以下方式解决上述问题:var u=require('下划线');var contents=fs.readFileSync(filepath.toString();var tplcontents=u.template(内容,{email:email});//编译