Handlebars

Subexpressions

EmberScreencasts.com

Episode 24

{{#link-to 'posts' 
  (query-params sortAscending=isAscending)
}}
{{#outer-expression arg1
  (subexpression subArg)
}}

Outer expression

  • Component
  • Handlebars Helper
  • Any mustache that takes an argument

subexpression

  • Handlebars Helper
//helpers/es-equal.js

export default Ember.Handlebars.makeBoundHelper(
  function(arg1, arg2){
    return arg1 == arg2;
  }
)


//something.hbs

{{#if (es-equal hatColor 'blue')}}
  "What a lovely hat!"
{{else}}
  "Have you no taste?"
{{/if}}
//helpers/es-and.js

export default Ember.Handlebars.makeBoundHelper(
  function(arg1, arg2){
    return arg1 && arg2;
  }
)

//helpers/es-not.js

export default Ember.Handlebars.makeBoundHelper(
  function(arg){
    return !arg;
  }
)
{{#if (es-and isSelectedSort 
              (es-not isAscending))}}
    Highlight up arrow
{{else}}
    Don't highlight up arrow
{{/if}}
{{#if (es-and isSelectedSort 
              (es-not isAscending)
              (car 
                (cdr
                   (list 
                      (es-and true false)
                      (es-not false)
                      true))))}}
    Highlight up arrow
{{else}}
    Don't highlight up arrow
{{/if}}

24: handlebars subexpressions

By Jeffrey Biles

24: handlebars subexpressions

  • 1,610