I'm having a problem with express and I don't know how to fix it. I would like to be able to pass information from the controller to a partial view (a header). The problem is that when I access a view other than the one I render in the controller, it breaks. How can I pass information to one view and make it work in all of them.
const indexController = (req, res) => {
let emailSession;
if(req.session.userLogged == undefined){
emailSession = "";
} else {
emailSession = req.session.userLogged.email
}
db.Users.findOne({
where: {email: emailSession}
}).then((data) => {
res.render('index', {data}) //I want here to send the same variable to all of my views that has the same header, not just the index view
)
}
<nav>
<% if(data.info == "something") {%>
<a href="">Dashboard</a>
<% } %>
</nav>