Open mjgs opened 5 years ago
I was wondering the same thing, but your way has two downsides
1). in app.js routers always referring to layout instead of actual template name
res.render('layout', locals);
2). we cannot extend custom styles tags inside layout.ejs (unless you want to put style tags in separate .ejs file, yikes!)
Comparing pug and ejs the big advantage with pug is 'blocks' and template layouts. So i was playing around with @mschwarzmueller 's node course, using includes to have a base template and i ended up simulating blocks as well.
And here is what i came up with https://github.com/dheeraj-br/ejs_layout_implementation with this approach we now have base template and 'blocks' in EJS (less restrictions than pug's entends, append and prepend IMHO)
I created this example while building my site after going down quite a nasty rat hole trying to use 3rd party libraries to create partials/layouts. In fact it's possible to create layouts using just includes and this example goes into a bit more detail than the current docs example, using express and variables to set the template path. I thought you might be interested in me adding it to the ejs repo examples folder?