Change .ejs extension to .html using Parse.com Express.js

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

How would I go about using .html extensions on my view files instead of .ejs when using Parse.com's Express.js?

I changed the EJS delimiters to <? and ?> because I'm used to them from PHP. That worked fine, but I can't seem to change the file extension for my view files:

I've tried the following:

var express = require('express'); var ejs = require('ejs'); var app = express();  ejs.open = '<?'; ejs.close = '?>';  app.set('view engine', 'ejs'); app.engine('.html', ejs.renderFile); app.set('views', 'cloud/views'); app.use(express.bodyParser());  app.get('/', function(req, res) {     res.render('Test', { message: 'Hello Express!' }); });  app.listen(); 

And I get an internal server error.

I've also tried eliminating this line with the same result:

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

回答1:

app.set('view engine', 'html'); app.engine('html', ejs.renderFile); 

So I did app.set to html and app.engine to html and it was working for me.



回答2:

this way works too:

app.set('view engine', 'html'); app.engine('html',require('ejs').renderFile); 

someone knows any problem using this way?



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!