ejs-locals icon indicating copy to clipboard operation
ejs-locals copied to clipboard

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

Open atuttle opened this issue 13 years ago • 0 comments

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.

atuttle avatar Nov 19 '12 15:11 atuttle