Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // How to use... note qoute syntax is important
- {{#ifcond type '==' 'document'}}
- <div class="icon-bg">
- <span class="icon icon-document"></span>
- </div>
- {{/ifcond}}
- {{#ifcond widget '!==' 'foobar'}}
- <p>I'm not a foobar</p>
- {{/ifcond}}
- // add this to your js file
- Handlebars.registerHelper('ifcond', function (v1, operator, v2, options) {
- switch (operator) {
- case '==':
- return (v1 == v2) ? options.fn(this) : options.inverse(this);
- case '===':
- return (v1 === v2) ? options.fn(this) : options.inverse(this);
- case '!==':
- return (v1 !== v2) ? options.fn(this) : options.inverse(this);
- case '<':
- return (v1 < v2) ? options.fn(this) : options.inverse(this);
- case '<=':
- return (v1 <= v2) ? options.fn(this) : options.inverse(this);
- case '>':
- return (v1 > v2) ? options.fn(this) : options.inverse(this);
- case '>=':
- return (v1 >= v2) ? options.fn(this) : options.inverse(this);
- case '&&':
- return (v1 && v2) ? options.fn(this) : options.inverse(this);
- case '||':
- return (v1 || v2) ? options.fn(this) : options.inverse(this);
- default:
- return options.inverse(this);
- }
- });
Add Comment
Please, Sign In to add comment