3

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!

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

express-ejs-layouts drives me crazy with this. If anything goes wrong in the controller or view, it reports that the first variable referenced in the view or layout is undefined. Basically I can never trust the error messages I get when using express-ejs-layouts.
0

in my case, I added the title variable to the res.render call, but had not restarted the server. The change was not picked up and threw the error mentioned until I restarted the server.

Something like nodemon can help avoid this problem while you are developing.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.