Skip to content

Instantly share code, notes, and snippets.

@scizers
Created December 8, 2014 07:25
Show Gist options
  • Save scizers/e6ca5e901d7686f23c2d to your computer and use it in GitHub Desktop.
Save scizers/e6ca5e901d7686f23c2d to your computer and use it in GitHub Desktop.
Generate Title from routes path in ejs
res.locals.titleGenerator = function () {
var urlPath = (req.route.path).split('/')
var urlName = urlPath[1];
function capitalizeEachWord(str) {
return str.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
if (urlName == '') {
return 'Welcome'
} else {
var humanName = S(urlName).humanize().s;
return (capitalizeEachWord(humanName));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment