node.jsexpressejs

Express layouts error - variable not defined


I am using express-ejs-layouts and am seeing the following error in the console log:

 >> 5|          <title><%= title %></title>
title is not defined

I do indeed have the following element defined in my layout.ejs file:

    <title><%= title %></title>

I am populating this variable from one of my route files:

router.get('/', function(req, res) {
    res.render('index', {
        title : 'Express'
    });
});

Any idea what I am missing? Thanks!


Solution

  • I figured this out. There was another variable (description) that was not defined. As soon as I set the 'description' variable this worked. Seems a bit odd that the error message would be for 'title' though.