-
-
Save vinitkumar/5779755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Render view helper | |
// if the request is coming from mobile and if you have a view | |
// with users.mobile.jade, then that view will be rendered | |
app.use(function (req, res, next) { | |
res._render = res.render | |
res.render = function (template, locals, cb) { | |
var ua = req.header('user-agent') | |
var fs = require('fs') | |
var view = app.get('views') + '/' + template + '.mobile.jade' | |
if (/mobile/i.test(ua) && fs.existsSync(view)) { | |
res._render(template + '.mobile', locals, cb) | |
} else { | |
res._render(template, locals, cb) | |
} | |
} | |
next() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment