Created
July 23, 2012 15:50
-
-
Save blake-simpson/3164344 to your computer and use it in GitHub Desktop.
unless_blank Handlerbars JS helper
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
// Uses same syntax as #if helper but initially returns false for falsey or empty string values. | |
Handlebars.registerHelper('unless_blank', function(item, block) { | |
return (item && item.replace(/\s/g,"").length) ? block.fn(this) : block.inverse(this); | |
}); | |
// Only the first 2 rows will be displayed. | |
data = { | |
rows: [ | |
'user_name': 'Blake', | |
'user_name': 'Joe', | |
'user_name': '', | |
'user_name': ' ', | |
'user_name': null | |
] | |
} | |
{{#unless_blank user_name}} | |
Welcome back, {{user_name}} | |
{{/unless_blank}} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment