Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
199
rated 0 times [  200] [ 1]  / answers: 1 / hits: 28817  / 12 Years ago, fri, april 13, 2012, 12:00:00

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?


More From » html

 Answers
4

Index has to be prefixed with your item name. In example:



<#if (index+1) < pages?size>,</#if>


should have been:



<#if (page_index+1) < pages?size>,</#if>

[#86259] Thursday, April 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rhett

Total Points: 671
Total Questions: 100
Total Answers: 102

Location: Hong Kong
Member since Tue, Oct 19, 2021
3 Years ago
rhett questions
Thu, Oct 28, 21, 00:00, 3 Years ago
Mon, Aug 2, 21, 00:00, 3 Years ago
Fri, Dec 11, 20, 00:00, 3 Years ago
Fri, Aug 7, 20, 00:00, 4 Years ago
Thu, Mar 26, 20, 00:00, 4 Years ago
;