Skip to content

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

@atuttle

Description

@atuttle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions