layout.ejs doesn't work on NodeJS app in Heroku

I have the usual nodejs express app...

var express = require('express');

var app = express.createServer(
    express.bodyParser()
);

app.configure( function () {
    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use("/public", express.static(__dirname + '/public'));
});

app.get('/', function (req, res) {
    res.render('index');
});

I have a index.ejs and layout.ejs in /views folder:

layout.ejs:

<!doctype html>
<html lang="en" manifest=""><head>
    <title>jQuery Plugin Demo</title>
</head>
<body>
    <div class="container container-fluid">
        <%- body %>
    </div>
</body>
</html>

index.ejs:

Hello world

index.ejs only renders the "Hello world" text without the surrounding layout.ejs wrapper. The ejs is working. It's able to find the correct .ejs template, but it's just ignoring the layout. I've also tried explictly adding layout file to app..

app.set('view options', { layout:'layout.ejs' }); 

All of this works fine locally, but not on Heroku. Here is my package.json:

{
  "name": "in1-test",
  "version": "0.0.1",
  "author": "Iatek",
  "dependencies": {
    "express": ">=2.5.x",
    "ejs": ">=0.7.x"
  },
  "engines": {
    "node": "0.6.x"
  }
}

Why no joy on the layout??? Thanks

I'm using express 3.x with ejs-locals and it works well. You just have to specify which layout to use:

login.ejs

<% layout('layout') -%>
<form>...</form>

layout.ejs

<body>
<h1>Hello</h1>
<%- body %>
</body>

https://npmjs.org/package/ejs-locals

When you deploy to Heroku it does an npm install for all your dependencies; because you have stated express >=2.5.x it will install the latest which is 3.0.0_betax. Express 3 does not have support for layouts in ejs (yet).

To fix remove the ">=" and specify the version of express that is in your local version.

As chovy said, ejs-locals can help you handle this if you want to upgrade to Express 3.x. I've got a github repo here that provides a bootstrapped project for Express 3.x, ejs, and twitter bootstrap:

https://github.com/cacois/node-express-twitter-bootstrap

Its a good starting point for a new app, or as an example of how to use ejs layouts with Express 3.x.