跳转到主要内容
myfreax
返回

Express框架–template模板

Express框架–template模板

Express框架–template模板

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

myfreax

  1. 暂无评论,快来抢沙发吧!