如何在一个 #list 中迭代多个项目序列或集合?

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

我有两个项目集合,我想迭代一个 <#list>

我试过如下但它给了我一个错误:

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

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

这是一个有点不寻常的数据结构,但只要确保两个列表的长度相等,您可以这样做:

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