[英]Why is this variable not getting passed to jade from my express app?
My express app has got the following code: 我的快速应用程序具有以下代码:
app.get('/dashboard', function (req, res) {
Student.findOne({
email: req.session.email
}).exec(function (err, studentData) {
if (studentData) {
console.log(studentData);
res.render('dashboard', {
info:{
username: studentData.username,
email: studentData.email,
roll: studentData.roll,
department: studentData.department,
regYear: studentData.regYear
}
});
} else {
res.render('index');
}
});
});
And my jade template has got the following code: 而且我的翡翠模板具有以下代码:
doctype html
html
head
meta(charset='UTF-8')
title I N C U B A T I O N
link(rel='stylesheet', href='/bower_components/Materialize/bin/materialize.css')
script(src='/bower_components/jquery/dist/jquery.min.js')
script(src='/bower_components/Materialize/bin/materialize.js')
link(rel='stylesheet', type='text/css', href='css/main.css')
script.
console.log(!{locals.info.username});
body
ul#slide-out.side-nav.fixed
li
.row.valign-wrapper.profile_picture
.col.s3
.col.s6
img.circle.responsive-img(src='http://1.bp.blogspot.com/_Mt4qyhflsHY/S8wCjflidQI/AAAAAAAAAhI/FiTJiysCYus/s1600/gravatar.jpg', alt='')
// notice the "circle" class
.col.s3
li
.row.valign-wrapper
p #{info.username}
a.button-collapse(href='#', data-activates='slide-out')
i.mdi-navigation-menu
I want to pass on the variables from my node app to the template but it's not getting passed. 我想将变量从节点应用程序传递到模板,但是没有传递。
What am I doing wrong here? 我在这里做错了什么?
Have you set your view engine to jade in express? 您是否已将视图引擎设置为翡翠快车?
app.set('view engine', 'jade');
http://expressjs.com/en/guide/using-template-engines.html http://expressjs.com/en/guide/using-template-engines.html
You don't have to prefix the variables with locals.
您不必在变量locals.
加上locals.
变量locals.
in jade. 在玉。 From the structure of your call to render
, it looks like you're setting info.username
, not locals.info.username
. 从调用render
的结构来看,您似乎正在设置info.username
,而不是locals.info.username
。
This means you should see your variable with 这意味着您应该看到带有
console.log(!{info.username});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.