Created
December 8, 2014 07:25
-
-
Save scizers/e6ca5e901d7686f23c2d to your computer and use it in GitHub Desktop.
Generate Title from routes path in ejs
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
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