Node.js express: confuse ejs template

I put the ejs template ejs in the views folder, for example:

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

so i am customizing my ejs template:

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

I draw my foo template as follows:

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

I want to use layout.html as a layout template, I also add the <%- body%> to layout.html but it doesn’t work, what I saw only returns the completed foo.html .

Why layout.html n't layout.html be the main layout? Or how can I install it on the layout of the wizard?

+3
source share
2 answers

Aha, you were simply deceived by the change of Express 3 in managing layouts. Official example: https://github.com/visionmedia/express/tree/master/examples/ejs Not updated.

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

+3
source

Try using ejs-locals, then you can do this in the login.ejs file:

 <% layout('layout') -%> <form></form> 
+2
source

Source: https://habr.com/ru/post/1501757/


All Articles