{{#helper args hashes}}
Calls a mustache helper function with a block, and optional inverse block.
{{#helper [args...] [hashName=hashValue...]}}BLOCK{{/helper}}
Calls a mustache helper function or a function with a block to render.
The template:
<p>{{countTo number}}{{num}}{{/countTo}}</p>
Rendered with:
{number: 5}
Will call the countTo
helper:
can.Mustache.registerHelper('madLib',
function(number, options){
var out = []
for(var i =0; i < number; i++){
out.push( options.fn({num: i+1}) )
}
return out.join(" ")
});
Results in:
<p>1 2 3 4 5</p>
Parameters
-
helper
{key}
A key that finds a helper function that is either registered or found within the current or parent context.
-
args
{key | String | Number}
Optional VariableSpace seperated arguments that get passed to the helper function as arguments. If the key's value is a:
- can.Observe - A getter/setter can.compute is passed.
- can.compute - The can.compute is passed.
function
- The function's return value is passed.
-
hashProperty
{String}
A property name that gets added to a helper options's hash object.
-
hashValue
{key | String | Number}
A value that gets set as a property value of the helper option argument's hash object.
-
BLOCK
{mustache}
A mustache template that gets compiled and passed to the helper function as the options argument's
fn
property.
{{#helper [args...] [hashName=hashValue...]}}BLOCK{{else}}INVERSE{{/helper}}
Calls a mustache helper function or a function with a fn
and inverse
block to
render.
The template:
<p>The bed is
{{isJustRight firmness}}
pefect!
{{else}}
uncomfortable.
{{/justRight}}</p>
Rendered with:
{firmness: 45}
Will call the isJustRight
helper:
can.Mustache.registerHelper('isJustRight',
function(number, options){
if(number > 50){
return options.fn(this)
} else {
return options.inverse(this)
}
return out.join(" ")
});
Results in:
<p>The bed is uncomfortable.</p>
Parameters
-
helper
{key}
A key that finds a helper function that is either registered or found within the current or parent context.
-
args
{key | String | Number}
Optional VariableSpace seperated arguments that get passed to the helper function as arguments. If the key's value is a:
- can.Observe - A getter/setter can.compute is passed.
- can.compute - The can.compute is passed.
function
- The function's return value is passed.
-
hashProperty
{String}
A property name that gets added to a helper options's hash object.
-
hashValue
{key | String | Number}
A value that gets set as a property value of the helper option argument's hash object.
-
BLOCK
{mustache}
A mustache template that gets compiled and passed to the helper function as the options argument's
fn
property. -
INVERSE
{mustache}
A mustache template that gets compiled and passed to the helper function as the options argument's
inverse
property.
Use
Read the use section of {{helper}} to better understand how:
Read how helpers that return functions can be used for rich behavior like 2-way binding.