I use a toolbox to create a simple JSON response (see code below). I need to put a comma after all the response elements except the last.
I believe that I need to use the TT iterator, but I do not understand. With this code, the comma is still printed at the end of the last element.
The problem is in the section containing
[% UNLESS outer.last && loop.last %],[% END %]
this should add a comma if the outer and inner loops are at the last iteration.
Any help regarding my mistake is greatly appreciated.
{ "success": true, "filesdata": [ [%~ USE outer = iterator(objects); FOREACH object IN outer; FOREACH rep IN object.reps; IF rep.rep == reptype %] { "id":"[% object.id | xml %]", "url":"[% rep.src | xml %]", "story":"[% object.story | xml %]" }[% UNLESS outer.last && loop.last %],[% END %] [%~ END; END; END ~%] ] }
source share