Skip to content

Instantly share code, notes, and snippets.

@blake-simpson
Created July 23, 2012 15:50
Show Gist options
  • Save blake-simpson/3164344 to your computer and use it in GitHub Desktop.
Save blake-simpson/3164344 to your computer and use it in GitHub Desktop.
unless_blank Handlerbars JS helper
// 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