# express-ejs-layouts > Layout support for ejs in express [![npm version](https://badge.fury.io/js/express-ejs-layouts.svg)](https://badge.fury.io/js/express-ejs-layouts) [![build status](https://secure.travis-ci.org/soarez/express-ejs-layouts.svg)](http://travis-ci.org/Soarez/express-ejs-layouts) ## Installation ```sh $ npm install express-ejs-layouts ``` ## Example Check the example folder. 1. `git clone https://github.com/soarez/express-ejs-layouts.git` 2. `cd express-ejs-layouts` 3. `npm install` 4. `node example` 5. Open http://localhost:3000/ ## Usage ```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); ``` ### `contentFor` 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
bar
foo
``` 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. ### Script blocks extraction 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