How to remove duplicate elements in an array using freemarker?

We can use freemarker sequences. Probably not super efficient but I’ve used this to group close to max size lines on invoices and such.

<#assign seen_style = []>
<#list record.item?sort_by("custcol_stylesort")  as lineitem>
   <#assign groupId = lineitem.item>
   <#if seen_style?seq_contains(groupId)> <!-- no if body is intentional; skips seen style -->
   <#else>
     <#assign seen_style = seen_style + [groupId]>
     <p>Do something with ${groupId}</p>
   </#if>
</#list>

Leave a comment

Your email address will not be published. Required fields are marked *