Hi, I am looking to test an iw_iterate iteration count to the size/length/count of its list in order to apply a different pattern to the last item in the container.
My goal is to to make a Json formated list and I need to not have a comma at the end of the last one.
I know how to iterate, how to have a counter and how to do if/else logic in the iterator but I don't know how to get the length (or count or size) of the dcr container/"list". I'm working in a .tpl file so I'm using iw_iterate.
I was thinking something like this:
<iw_iterate list="dcr.deals.sale_item" var="item" iteration="counter">
<iw_if expr=' {iw_value name="$counter"/} le "(number of items in the $list - 1)" ' >
<iw_then>
{
something,
something,
something
},
</iw_then>
<iw_else>
{
something,
something,
something
}
</iw_else>
</iw_if>
</iw_iterate>
Unfortunalty I don't know perl (and don't really have time to learn it thurouhly right now) but if there was some kind of small script that I can use that would be great. The internet seems to say that getting the scalar of an array is the way to go but I don't understand how perl syntax works in context to an iterator.
Thanks,
Greg