[英]Why is this variable not getting passed to jade from my express app?
我的快速應用程序具有以下代碼:
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');
}
});
});
而且我的翡翠模板具有以下代碼:
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
我想將變量從節點應用程序傳遞到模板,但是沒有傳遞。
我在這里做錯了什么?
您是否已將視圖引擎設置為翡翠快車?
app.set('view engine', 'jade');
您不必在變量locals.
加上locals.
變量locals.
在玉。 從調用render
的結構來看,您似乎正在設置info.username
,而不是locals.info.username
。
這意味着您應該看到帶有
console.log(!{info.username});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.