Before Express can render template files, the following application settings have to be set.

Express 渲染模板文件之前必须给应用设置模板引擎

  • views, the directory where the template files are located. Eg: app.set('views', './views')
  • view engine, the template engine to use. Eg: app.set('view engine', 'jade')

安装模板引擎

npm install jade --save

设置模板引擎

app.set('view engine', 'jade');

创建模板

html
  head
    title!= title
  body
    h1!= message

渲染模板

app.get('/', function (req, res) {
  res.render('index', { title: 'Hey', message: 'Hello there!'});
});

Learn More

eveloping-template-engines

如果你喜欢我们的内容可以选择在下方二维码中捐赠我们,或者点击广告予以支持,感谢你的支持