Express layouts error - variable not defined

旧时模样 提交于 2019-12-12 22:18:06

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/25433238/express-layouts-error-variable-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!