Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traversing two sequences in Freemarker

I am new to FreeMarker and I am working on a project which uses it.

The scenario is, I have two lists in FreeMarker which I am getting from the backend(say firstNames & lastNames. Now what I want to do is, I want to loop through these lists and access the values from both lists at the same index.

I want the output to be something like

<#assign firstNames = fNames/>
<#assign lastNames = lNames/>
<body>
    <table>
        <loop from 0 to 5>
        <tr>
            <td>Hello firstNames[i] lastNames[i]</td>
        </tr>
        </loop>
    </table>
</body>

For simplicity I will assume that the length of the lists will always be the same(say 5).

Is there a way to achieve this??

like image 305
Sayan Avatar asked Nov 28 '25 08:11

Sayan


1 Answers

Like this:

<#list firstNames as firstName>
  Hello ${firstName} ${lastNames[firstName?index]}
</#list>
like image 194
ddekany Avatar answered Nov 29 '25 21:11

ddekany