Han
7 years agoAce
Add a separator if freemarker loop has more than one item
I am new to logic in freemarker and having trouble adding a separator in a loop if there is more than one item. My current code below is adding a separator, but it appears after my items; <...
- 7 years ago
It would resolve you problem
${userType?keep_before_last("|")}
I may create an issue if a user does not have any role but I think every user will have at least one role. Right?
Here is an updated version. Here is the output https://prnt.sc/jsccwr
<#assign userTypeCount = 0> <#assign userType = ""/> <#list restadmin("/users/id/${user.id}/roles").roles.role as role> <#assign userType += role.name > <#assign userTypeCount ++> <#-- only add separator if user has more than one role --> <#assign userType += ' | '> </#list> ${userType} ${userType?keep_before_last("|")}