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

你的欣赏是我最大的动力

Yanxiong Huang

My name is Yanxiong Huang. graduated from Nanyang middle school.Love Linux,familiar with Node.js,Docker,Serverless... and more Web technology.Contact Me:QQ 31356617;Email:huangaynxiong2013@gmail.com

guangzhou,china http://www.myfreax.com

乐在分享