大佬教程收集整理的这篇文章主要介绍了Node.js – Expressjs中间件扩展res.render,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
app.use(function(req,res,next){ res.render2 = function (view,locals,fn) { res.render(view,_.extend(setTings.template_defaults,locals),fn); }; next(); });
app.locals
:
app.locals(setTings.template_defaults);
与res.locals
和res.render
一起,Express已经能够为您合并价值:
// locals for all views in the application app.locals(setTings.template_defaults); // middleware for common locals with request-specific values app.use(function (req,next) { res.locals({ // e.g. session: req.session }); next(); }); // and locals specific to the route app.get('...',function (req,res) { res.render('...',{ // ... }); });
以上是大佬教程为你收集整理的Node.js – Expressjs中间件扩展res.render全部内容,希望文章能够帮你解决Node.js – Expressjs中间件扩展res.render所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。