本文介绍了在 Express 中使用 HTML 而不是 Jade的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Node.JS 中使用 Express 时摆脱 Jade?我只想使用纯 html.在其他文章中,我看到人们推荐 app.register(),它现在在最新版本中已弃用.
How to I get rid of Jade while using Express with Node.JS? I want to just use plain html. In other articles I have seen that people recommended app.register() which is now deprecated in the latest version.
推荐答案
你可以这样做:
安装 ejs:
Install ejs:
npm install ejs
将 app.js 中的模板引擎设置为 ejs
Set your template engine in app.js as ejs
// app.js
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
现在在你的路由文件中你可以分配模板变量
Now in your route file you can assign template variables
// ./routes/index.js
exports.index = function(req, res){
res.render('index', { title: 'ejs' });};
然后您可以在/views 目录中创建您的 html 视图.
Then you can create your html view in /views directory.
这篇关于在 Express 中使用 HTML 而不是 Jade的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!