How to get list items by index in freemarker template?
Tested online, the following works well.
Input:
someList = ["2019-12-16", 3]
Template:
<ul>
<li>${someList[0]}</li>
<li>${someList[1]}</li>
</ul>
Output:
<ul>
<li>2019-12-16</li>
<li>3</li>
</ul>
Yes, you can easily use the index to get at an item like ${fields[i]}
. You might want to loop over the indexes using something like:
<#list 0..fields?size-1 as i>
${fields[i]}
</#list>
Alternatively, you can just list over a sequence without the index like:
<#list fields as field>
${field}
</#list>
you can use inbuilt index property of FMT: eg:
<#list ['a', 'b', 'c'] as i> ${i?index}: ${i} </#list>