Skip to content

misejs/express-layout

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-layout Build Status

Adds layout support to Express

Installation

npm install express-layout

Usage

Express-layout is a middleware that overrides the standard res.render() method. Initialize it with:

var express = require('express'),
    layout = require('express-layout'),
    app = express();

app.use(layout());

By default, res.render() will render the view and pass the string of html as a body variable to a file named layout in the views folder. You can alter the layout used by passing an option. For example:

res.render('hello-world', { layout: 'alternative' });

If you pass false, the view will not render within a layout.

You can set a global default layout name and/or directory in which to search for layout files. These can be set by passing an options hash to the middleware on instantiation (layout and layouts are the keys, respectively). Alternatively, you can set them using Express' built-in global settings:

app.set('layouts', './views/layouts');
app.set('layout', 'default');

Finally, an example template in jade might look like this:

doctype 5
html(lang="en")
  head
    title Hello
  body!= body

About

Adds layout support to Express

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%