I have been reading up on best method in smarty to set every 4th item in the loop a class, and came across the use of "interation" however the example code below is kind of working but it is apply the class to everything after the 4th one and im wanting to apply a last class on every 4th one. Is this possible using this method?
{foreach from=$product.image_pairs item="image_pair" name="additional_images"}
{if $image_pair}
{if $image_pair.image_id == 0}
{assign var="img_id" value=$image_pair.detailed_id}
{else}
{assign var="img_id" value=$image_pair.image_id}
{/if}
{if $smarty.foreach.additional_images.iteration is div by 4}
{assign var="last_image" value="last"}
{/if}
{include file="common_templates/image.tpl" images=$image_pair object_type="detailed_product" link_class="cm-thumbnails-mini $last_image" image_width=$th_size image_height=$th_size show_thumbnail="Y" show_detailed_link=false obj_id="`$preview_id`_`$img_id`_mini" make_box=true wrap_image=true}
{/if}
{/foreach}
Result:
<a class="">content</a>
<a class="">content</a>
<a class="">content</a>
<a class="">content</a>
<a class="last">content</a>
<a class="last">content</a>
<a class="last">content</a>
{assign var="last_image" value="last"}
Will assign this variable on 4th iteration, and this will prevail for next iterations. You should add else
and assign empty string to this variable.