function(arg..., options)
Parameters
-
arg
{* | can.compute(getterSetter, context)}
Optional Variable
Arguments passed from the tag. After the helper
name, any space seperated keys, numbers or
strings are passed as arguments. Keys that
read an observable value are passed as can.compute's.
-
An options object
that gets populated with optional:
fn
and inverse
section rendering functions
- a
hash
object of the maps passed to the helper
Returns
{documentFragment | String | contentArray | function(HTMLElement)}
The content to be inserted into
the template.
This
{can.stache.context}
The context the helper was
called within.
Use
The following template:
Rendered with
Will call a
madLib
helper with the following arguements.While keys are normally resolved as basic objects like strings or numbers, there are special cases where they act differently than a normal tag. Whenever a can.compute or function object is an argument for a helper, the original object is used as the argument instead of the value that the function returns.
If a key represents a can.Map attribute, it is converted to a can.compute getter/setter function. This enables 2-way binding helpers.
For example, the following helper two-way binds an input element's value to a can.compute:
And used by the following template:
And rendered with:
Returning an element callback function
If a helper returns a function, that function is called back after the template has been rendered into DOM elements. This can be used to create stache tags that have rich behavior.
If the helper is called within a tag like:
The returned function is called with the
<ul>
element:If the helper is called between tags like:
The returned function is called with a temporary element. The following helper would be called with a temporary
<li>
element:The temporary element depends on the parent element. The default temporary element is a
<span>
element.