Skip to content

Instantly share code, notes, and snippets.

@thehungrycoder
Last active December 13, 2015 16:49
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 thehungrycoder/4943126 to your computer and use it in GitHub Desktop.
Save thehungrycoder/4943126 to your computer and use it in GitHub Desktop.
Handlebars.registerHelper('short_string', function(context, options){
//console.log(options);
var maxLength = options.hash.length || 100;
var trailingString = options.hash.trailing || '';
if(context.length > maxLength){
return context.substring(0, maxLength) + trailingString;
}
return context;
});
/**
* usages (handlebars)
* {{short_string this}}
* {{short_string this length=150}}
* {{short_string this length=150 trailing="---"}}
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment