Helper Expression
Deprecated 4.15.0
Use [can-stache.expression.call] instead.
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
hash
object.If an
EXPRESSION
reads an observable, a compute will be passed tomethod
.
Use
A helpers expression calls a function looked up in the [can-view-scope.Options helpers scope] followed by the scope. It looks like:
<!-- Template -->
<h1>{{pluralize type ages.length}}</h1>
{
pluralize: function( type, count ) {
return "data-pluralize";
},
todos: new List( [ 22, 32, 42 ] ),
type: "age"
}
{
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>
{
todos: new List( [ 22, 32, 42 ] ),
type: "age"
}
{
pluralize: function( helperOptions ) {
return helperOptions.hash.type + ( helperOptions.hash.count() === 1 ? "" : "s" );
}
}
<!-- Result -->
<h1>Ages</h1>