×

Please give details of the problem

Skip to content

How to make a loop

Let's try to make a loop over an array to create a new variable 'list_firstnames' containing firstnames.

<#assign my_array = [
    {"firstname": "Name 1", "lastname": "Lastname 1"}, 
    {"firstname": "Name 2", "lastname": "Lastname 2"},
    {"firstname": "Name 3", "lastname": "Lastname 3"}
]> 
<#assign list_firstnames = "">

<#list my_array as x>
    <#assign list_firstnames = list_firstnames + " " + x.firstname>
</#list>

${list_firstnames}

Result:

Name 1 Name 2 Name 3