Iterators
- 1 each
- 2 this
- 3 @index
- 4 @key
- 5 First and last
- 6 Nested Blocks
each
Like a loop, you can iterate over a list using the built-in #each
helper. Inside the block, you can use this to reference the element being iterated over.
{{#each people}}
{{this}}
{{/each}}
when used with this context:
{
people: [
"Yehuda Katz",
"Alan Johnson",
"Charles Jolley",
],
}
will result in:
Yehuda Katz
Alan Johnson
Charles Jolley
this
You can use the this
expression in any context to reference the current context.
You can optionally provide an else
section which will display only when the list is empty.
@index
When looping through items in each, you can optionally reference the current loop index via {{@index}}
.
@key
Additionally for object iteration, {{@key}}
references the current key name:
First and last
The first and last steps of iteration are noted via the @first
and @last
variables when iterating over an array.
Nested Blocks
Nested each blocks may access the iteration variables via depth based paths. To access the parent index, for example, {{@../index}}
can be used.