Guest User

Untitled

a guest
Jan 16th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. // How to use... note qoute syntax is important
  2. {{#ifcond type '==' 'document'}}
  3. <div class="icon-bg">
  4. <span class="icon icon-document"></span>
  5. </div>
  6. {{/ifcond}}
  7.  
  8. {{#ifcond widget '!==' 'foobar'}}
  9. <p>I'm not a foobar</p>
  10. {{/ifcond}}
  11.  
  12.  
  13. // add this to your js file
  14. Handlebars.registerHelper('ifcond', function (v1, operator, v2, options) {
  15. switch (operator) {
  16. case '==':
  17. return (v1 == v2) ? options.fn(this) : options.inverse(this);
  18. case '===':
  19. return (v1 === v2) ? options.fn(this) : options.inverse(this);
  20. case '!==':
  21. return (v1 !== v2) ? options.fn(this) : options.inverse(this);
  22. case '<':
  23. return (v1 < v2) ? options.fn(this) : options.inverse(this);
  24. case '<=':
  25. return (v1 <= v2) ? options.fn(this) : options.inverse(this);
  26. case '>':
  27. return (v1 > v2) ? options.fn(this) : options.inverse(this);
  28. case '>=':
  29. return (v1 >= v2) ? options.fn(this) : options.inverse(this);
  30. case '&&':
  31. return (v1 && v2) ? options.fn(this) : options.inverse(this);
  32. case '||':
  33. return (v1 || v2) ? options.fn(this) : options.inverse(this);
  34. default:
  35. return options.inverse(this);
  36. }
  37. });
Add Comment
Please, Sign In to add comment