Layout support for ejs in express.
npm install express-ejs-layouts> Layout support for ejs in express


``sh`
$ npm install express-ejs-layouts
Check the example folder.
1. git clone https://github.com/soarez/express-ejs-layouts.gitcd express-ejs-layouts
2. npm install
3. node example
4.
5. Open http://localhost:3000/
`javascript
var express = require('express');
var expressLayouts = require('express-ejs-layouts');
var app = express();
app.set('view engine', 'ejs');
app.use(expressLayouts);
app.get('/', function(req, res) {
var locals = {
title: 'Page Title',
description: 'Page Description',
header: 'Page Header'
};
res.render('the-view', locals);
});
app.listen(3000);
`
A view
`ejs`
tyler
<%- contentFor('foo') %>
club
<%- contentFor('bar') %>
fight
With a layout
`ejs`
<%-bar%> <%-foo%>
<%-body%>
Renders
``
fight club
tyler
As another example, consider this view:
`html`
foo
<%- contentFor('pageSectionA') %>
bar
<%- contentFor('pageSectionB') %>
baz
Using it with this layout:
`html`<%- pageSectionA %><%- body %>
Will render:
`html`barfoo
Notice that the difference between using <%- pageSectionA %> and <%-defineContent('pageSectionA')%> is that the former will generate an error if the view doesn't define content for this section.
If you like to place all the script blocks at the end, you can do it like this:
`javascript`
app.set("layout extractScripts", true)
A view
`html
something