Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created January 16, 2013 18:54
Show Gist options
  • Save kara-ryli/4549717 to your computer and use it in GitHub Desktop.
Save kara-ryli/4549717 to your computer and use it in GitHub Desktop.
A simple handlebars helper that enables testing of value equality. String, number and boolean values are supported.
{
"tests": [
{ "agree": "yes" },
{ "agree": "no" }
]
}
Handlebars.registerHelper("if_eq", function (test, options) {
return (test === options.hash.value) ? options.fn(this) : options.inverse(this);
}, true);
<p>I agree.</p>
<p>I disagree.</p>
{{#tests}}
{{#if_eq agree value="yes"}}
<p>I agree.</p>
{{#else}}
<p>I disagree.</p>
{{/if_eq}}
{{/tests}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment