Reputation: 7580
I want to change class of some menu items based on the current url being viewed by user in expressjs app. I am using ejs templating system in expressjs How do i pass current url and mangage current view class in links? Should I pass current url vale in each res.render? or is some variable passed in view that can be used?
Upvotes: 2
Views: 3255
Reputation: 7580
We can actually use
//pass user data
app.use(function(req, res, next) {
res.locals.variable = req.variable;
next();
});
and access the variable in view file.
Upvotes: 5
Reputation: 17803
you can pass the actual class or an indicator for which class to use as a template variable in res.render instead of passing the url and doing the actual parsing within the template.
Upvotes: 0