hh54188
hh54188

Reputation: 15626

Node.js express: confuse about ejs template

I put my ejs template file in views folder like:

views
|
|--foo.html
|
|--layout.html

so I config my ejs template:

app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);  

I render my foo template by this:

res.render('foo.html', {title: 'test'});

I want use layout.html as the master layout template, I also add <%- body%> tag in layout.html, but is doesn't work, what I saw is only return the ended foo.html.

Why the layout.html can't be the master layout?Or how can I set it to the master layout?

Upvotes: 3

Views: 7854

Answers (2)

3on
3on

Reputation: 6339

Ahah you just got tricked by Express 3 change in layout management. The official example: https://github.com/visionmedia/express/tree/master/examples/ejs Has not been updated.

In Jade you now have to use blocks and extend the layout. http://www.devthought.com/code/use-jade-blocks-not-layouts/

Upvotes: 3

chovy
chovy

Reputation: 75666

Try to use ejs-locals then you can do this in a login.ejs file:

<% layout('layout') -%>
<form></form>

Upvotes: 2

Related Questions