我可以从登录中获取会话变量id并将其设置为id,但我不确定如何在页面加载到句柄页面时传递变量。
我注释掉res.send我只是想看看是否会加载emailid,它确实加载了。我已经查看了一些示例,但仍不确定如何将变量直接传递到handlebars / html中的{{username}}点。
<!--Where the city and state info will be inputted -->
<div class="row">
<div class="col-sm-3">
<form>
<p>Search for parking</p>
<input id="location-input" type="textbox" placeholder="Enter a location" />
<br />
<br />
<!--When Clicked will push all the selected information above to GET API responses -->
<button id="submit-button" value="submit">Submit</button>
</form>
<br />
<br />
<div id="test">
Currently Logged in as: <br /> {{username}}
</div>
<br />
</div>
// goes to the application folder and checks to see if authenticated
app.get("/user", application.IsAuthenticated, function(req, res) {
// to help organize, some of the handlebars are within folders
var username = req.user.username;
// res.send(username);
res.render('./users/user');
});
答案 0 :(得分:0)
使用res.render
秒参数将数据传递到视图:
res.render('./users/user', { username: username });
来自docs:
呈现view
并将呈现的HTML字符串发送到客户端。可选参数: