Sections
can.stache.Sections
Sections ({{#key}}
followed by [can.stache.helpers.close {{/key}}]
) have multiple uses
depending on what type of object is passed to the section. In all cases, using a section will change
the current context.
The most basic form of section will simply render a section of code if the key referenced is considered truthy (has a value):
Whenever the key doesn't exist or the value is falsey, the section won't be rendered:
However, this scenario can be covered through the use of an inverse section (
[can.stache.helpers.inverse {{^key}}]
followed by[can.stache.helpers.close {{/key}}]
):Iteration
There is a special case for sections where the key references an array. In this case, the section iterates the entire array, rendering the inner text for each item in the array. Arrays are considered truthy if they aren't empty. The
{{.}}
tag will reference the current item within the array during iteration (which is primarily used when the items in the array are primitives like strings and numbers).