Each

The each statement allows you to loop over an array of items. When using data such as the following, you can loop over each item.

Router.get('/', client.response.render('each.mix', {
  items: ['a', 'b', 'c']
}))

Values

An each can be used where only the value is retrieved into a variable like this:

<each :="value in {{$items}}">
  <p>{{$value}}</p>
</each>

When executed the following output will be generated.

<p>a</p>
<p>b</p>
<p>c</p>

Key value pair

A key can also be used, the key and value just need to be placed withing brackets separated by a coma.

<each :="[key, value] in {{$items}}">
  {{$key}}: {{$value}}
</each>

When executed the following output will be generated.

<p>0: a</p>
<p>1: b</p>
<p>2: c</p>

each ... else

Sometimes an array can be empty and if it is you can always catch that and display something which is why there is the else statement.

Router.get('/', client.response.render('each.mix', {
  items: []
}))
<each :="value in {{$items}}">
  <p>{{$value}}</p>
</each>
<else>
  <span>The array was empty.</span>
</else>