我的快递应用程序有以下代码:
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');
}
});
});
我的jade模板有以下代码:
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
我想将变量从我的节点应用程序传递给模板,但它没有被传递 我在这里做错了什么?
答案 0 :(得分:0)
您是否已将视图引擎设置为快递中的玉?
app.set('view engine', 'jade');
答案 1 :(得分:0)
您不必在玉石中使用locals.
为变量添加前缀。从您拨打render
的结构来看,您似乎正在设置info.username
,而不是locals.info.username
。
这意味着你应该用
看到你的变量console.log(!{info.username});