Express框架–template模板
Express 渲染模板文件之前必须给应用设置模板引擎
1 min read
By
myfreax

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!'});
});