[转]更改ejs模板后缀.ejs为.html

三种写法

1,express老写法,3.*已经不支持

[javascript]view plaincopyprint?在CODE上查看代码片派生到我的代码片
 
  1. app.register('.html', require('ejs'));  
  2. app.set('view engine', 'ejs');  




2,

[javascript]view plaincopyprint?在CODE上查看代码片派生到我的代码片
 
  1. app.engine('.html', require('ejs').renderFile);  
  2. app.set('view engine', 'html');  




3,

[javascript]view plaincopyprint?在CODE上查看代码片派生到我的代码片
 
  1. app.engine('.html', require('ejs').__express);  
  2. app.set('view engine', 'html');  



2和3 在 express.js 3.* 都可以使用


注意:在路由里,可以省去 index.html的后缀,直接写index即可,但是在 视图里 include的时候,还是需要写上.html的后缀,否则报错
PS:Express变动太大,不成熟呀

posted on 2015-08-12 09:31  neights  阅读(427)  评论(0编辑  收藏  举报

导航