I am having a hard time trying to pass an object to the layout of my project in order to get a list of categories i need to show in the navbar. I have been trying o couple of solutions here and all relates on using a policy and assigning res.locals.myVar = someObj, the problem is that res.locals and also using req.options.locals.myVar are only available in the controller action's view and not the layout
So far i got this.
// getRoomList POLICY
Room.find().exec(function(err, rooms) {
if (err) {
return res.badRequest('Something went wrong.');
}
if (rooms) {
res.locals.roomlist = rooms;
next();
} else {
res.notFound();
}
});
// config/policies
'*': 'getRoomList'
// In layout.ejs
<%= roomlist %>
Aucun commentaire:
Enregistrer un commentaire