express - What is meaning of locals in res.render (node.js)? -
what difference between below 2 code block in node.js (express + ejs)?
res.render('demo', {locals:{"variable":data}});
and
res.render('demo', {"variable":data});
when use one? can 1 please me out in this.
the correct way of passing variables view wollowing
res.render('demo', {"variable":data});
then have objet res.locals
can append data , passed view.
for example if have middlewere authentication, can set auth variables before request arrives in route.
app.use(function(req, res, next){ res.locals.user = req.user; res.locals.authenticated = ! req.user.anonymous; next(); });
Comments
Post a Comment