Helper Expression
method [EXPRESSION...]
Calls method with zero or many arguments where each argument
is a space separated
EXPRESSION.
{{method 1 key call() hashProp=hashValue}}
Parameters
- EXPRESSION
{Literal Expression|KeyLookup Expression|Hash Expression|Call Expression}:An expression that will be passed as an argument to
method.All Hash Expressions will be collectively added to the helperOptions’s
hashobject.If an
EXPRESSIONreads an observable, a compute will be passed tomethod.
Use
A helpers expression calls a function looked up in the helpers scope followed by the scope. It looks like:
<!-- Template -->
<h1>{{pluralize type ages.length}}</h1>
/* Data */
{
pluralize: function(type, count){
return "data-pluralize"
},
todos: new List([22,32,42]),
type: "age"
}
/* Helpers */
{
pluralize: function(type, count){
return type+(count() === 1 ? "" : "s")
}
}
<!-- Result -->
<h1>Ages</h1>
Helper expression arguments that are observable are passed a compute. This is in contrast to Call expressions that get passed the value.
Helper expression arguments are space separated. If a Hash expression is an argument, the hash properties and values will be added to the helper options object. For example:
<!-- Template -->
<h1>{{pluralize word=type count=ages.length}}</h1>
/* Data */
{
todos: new List([22,32,42]),
type: "age"
}
/* Helpers */
{
pluralize: function(helperOptions){
return helperOptions.hash.type+(helperOptions.hash.count() === 1 ? "" : "s")
}
}
<!-- Result -->
<h1>Ages</h1>