{{#helper args hashes}}
Calls a stache helper function with a block, and optional inverse block.
{{#helper [args...] [hashName=hashValue...]}}BLOCK{{/helper}}
Calls a stache 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.stache.registerHelper('countTo',
function(number, options){
var out = [];
for(var i =0; i < number; i++){
var docFrag = options.fn({num: i+1});
out.push( docFrag.textContent );
}
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 [can.stache.context 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.Map - 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
{stache}
A stache 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 stache 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.stache.registerHelper('isJustRight',
function(number, options){
if(number > 50){
return options.fn(this);
} else {
return options.inverse(this);
}
});
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 [can.stache.context 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.Map - 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
{stache}
A stache template that gets compiled and passed to the helper function as the options argument's
fn
property. -
INVERSE
{stache}
A stache 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.