I’m writing a JS Array of objects in a Freemarker template. But I am having serious issues not including a comma after the last item.
<#assign pages = module.pages.page>
wh.pages = [
<#list pages as page>
{"name" : "${page.@name}", "href" : "${page.@href}"}
<#if (index+1) < pages?size>,</#if>
</#list>
]
So during the list repeat, while index + 1 is less than the length/size of the pages variable, it should write a comma. So that when it equals the size, it should omit the comma.
So how can this be achieved?
Index has to be prefixed with your item name. In example:
should have been: