Express版式错误-变量未定义 [英] Express layouts error - variable not defined
本文介绍了Express版式错误-变量未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用express-ejs-layouts,并且在控制台日志中看到以下错误:
I am using express-ejs-layouts and am seeing the following error in the console log:
>> 5| <title><%= title %></title>
title is not defined
我确实在layout.ejs中定义了以下元素文件:
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!
推荐答案
我知道了。还有一个未定义的变量(描述)。设置描述变量后,此功能便开始起作用。错误消息似乎是针对 title的,这有点奇怪。
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.
这篇关于Express版式错误-变量未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文