Search code examples
freemarker

How to iterate multiple sequences or collections of the items in one single #list?


I have two collections of the items and I want to iterate over one single <#list>.

I tried as follows but it gives me an error:

<#list [tags, categories] as entry>
    <p>${entry.category}</p>
    <p>${entry.tag}</p>
</#list>

Expected hash. entry evaluated instead to freemarker.template.SimpleSequence


Solution

  • That's a somewhat unusual data structure, but as far as something assures that the two lists has equal length, you could do this:

    <#list categories as category>
      <p>${category}</p>
      <p>${tags[category?index]}</p>
    </#list>