Last active
December 13, 2015 16:49
-
-
Save thehungrycoder/4943126 to your computer and use it in GitHub Desktop.
This file contains hidden or 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('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