1. Handlebars Helpers
  2. Each

Handlebars Helpers

Each

Loops over an array or object

NOTE

Example Looping over an object

This example takes the data submitted on the fields of the action.
It then loops over the data and converts it to a CSV formatted text value saved in stubpost_data_csv.

Example definition:

{
text
:
Field Name,Field Value {{#each stubpost.data}}{{@key}},{{this}} {{/each}}

Action context:

{
stubpost
:
{
data
:
{
firstname
:
Stuart
lastname
:
Procner

Substituted definition

{
text
:
Field Name,Field Value firstname,Stuart lastname,Procner

Example Looping over an array

This example loops over and array and outputs each text value.

Example definition:

{
list_of_items
:
{{#each stubpost.data.array_of_items}}{{this}},{{/each}}

Action context:

{
stubpost
:
{
data
:
{
array_of_items
:
[
3 items  
0
:
milk
1
:
bread
2
:
cheese

Substituted definition

{
list_of_item
:
milk,bread,cheese,

Example Looping over an object with nested values

This example loops over an array of objects and outputs certain values.

Example definition:

{
list_of_firstnames
:
{{#each stubpost.data.people}}{{this.firstname}},{{/each}}

Action context:

{
stubpost
:
{
data
:
{
people
:
[
2 items  
0
:
{
firstname
:
Stuart
lastname
:
Procner
1
:
{
firstname
:
John
lastname
:
Doe

Substituted definition

{
list_of_firstnames
:
Stuart,John,