Created
December 16, 2014 20:34
-
-
Save sshadmand/a3257ab23d3a76017431 to your computer and use it in GitHub Desktop.
Handlebar Helpers: Truncate Words
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
Handlebars.registerHelper('truncwords', function(text, length) { | |
words = text.split(" "); | |
new_text = text; | |
if (words.length > length){ | |
new_text = ""; | |
for (var i = 0; i <= length; i++) { | |
new_text += words[i] + " "; | |
} | |
new_text = new_text.trim() + "..." | |
} | |
return new_text; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment