Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 670
AJB Avatar asked Feb 21 '14 00:02

AJB


People also ask

Can EJS replace HTML?

html file rendered via Express, you can use res. render() with HTML files by creating a new View Engine in Express and then using that. The only requirement is that ejs is installed via npm i --save ejs . We need the ejs package directly because you'll need the renderFile() function for our new html view engine.

How do I link an EJS file to an HTML file?

To link the ejs pages to either html, php pages, you need to go to the app. js file and set the view engine correspondingly. app. set('view engine', 'ejs'); app.


1 Answers

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.

like image 135
jemiloii Avatar answered Oct 13 '22 01:10

jemiloii