使用Express将请求传递给每个Swig模板
是否可以将request/req对象传递给我呈现的每个模板,这样我就不必在每个render()方法中将其作为本地对象传递?您可以使用它 在路由之前的某个位置插入以下中间件:使用Express将请求传递给每个Swig模板,express,swig-template,Express,Swig Template,是否可以将request/req对象传递给我呈现的每个模板,这样我就不必在每个render()方法中将其作为本地对象传递?您可以使用它 在路由之前的某个位置插入以下中间件: app.use(function(req, res, next) { res.locals.req = req; next(); }); 这将req作为模板中的变量公开。您可以使用它 在路由之前的某个位置插入以下中间件: app.use(function(req, res, next) { res.locals
app.use(function(req, res, next) {
res.locals.req = req;
next();
});
这将req
作为模板中的变量公开。您可以使用它
在路由之前的某个位置插入以下中间件:
app.use(function(req, res, next) {
res.locals.req = req;
next();
});
这将req
作为模板中的变量公开