Skip to content

Instantly share code, notes, and snippets.

@sshadmand
Created December 16, 2014 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshadmand/a3257ab23d3a76017431 to your computer and use it in GitHub Desktop.
Save sshadmand/a3257ab23d3a76017431 to your computer and use it in GitHub Desktop.
Handlebar Helpers: Truncate Words
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