RandomEtc / ejs-locals

Express 3.x layout, partial and block template functions for the EJS template engine.
298 stars 63 forks source link

Passing a variable named "body" to a view when using a layout causes that variable to render as the layout body #22

Open atuttle opened 11 years ago

atuttle commented 11 years ago

views/layout.ejs:

<!DOCTYPE html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <%- body -%>
  </body>
</html>

views/post.ejs:

<% layout('layout') -%>
<h1><%= title %></h1>
<p><%= body %></p>

Route:

exports.index = function(req, res){
    res.render('index', { title: 'this is a test', body: 'test body' } );
};

Renders:

<!DOCTYPE html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    test body
  </body>
</html>

Expected:

<!DOCTYPE html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <h1>this is a test</h1>
    <p>test body</p>
  </body>
</html>

I've since changed my view to use "content" instead of "body" but thought it was best to bring this up. If it's expected behavior, you might want to add it to the readme.