Skip to content

icaliman/express-layouts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

express-layouts

Simple Layout Support for Express

Installation

npm install express-layouts --save

Usage Example

app.js

var express = require('express'),
    expressLayouts = require('express-layouts'),
    app = express();

app.use(expressLayouts);

app.set('views', 'cloud/views');
app.set('view engine', 'ejs');
app.set('layout', 'my-default-layout'); // defaults to 'layout'

app.get('/', function(req, res) {
  res.render('index'); // will use 'my-default-layout'
});

app.get('/hello', function(req, res) {
  res.render('hello', {
    layout: 'home-layout', // use home-layout
    message: 'Hello world!'
  });
});

app.listen();

home-layout.ejs

<html>
  <head>
    <title>Sample App</title>
  </head>
  <body>
    <h1>Home layout example</h1>
    <%- body %>
  </body>
</html>

hello.ejs

<p><%= message %></p>

About

Simple Layout Support for Express

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published