Smarty Template : Multiple Column Loop

Submitted by:Jhon Jhon

Date added:26 November, 2012


Take array and create multiple columns, define divisible by value ($divis) from total results then use modulus within the loop. This example shows multiple columns for unordered list items.

Tags: loop

Code Snippet:

    <div class="bullet-text">
{{assign var="cnt" value=$results|@count }}

{{ math equation="cnt/3" cnt=$results|@count assign=divis }}
Total Count: {{$cnt}}
Divided by 3: {{$divis}}

<ul class="col">
{{section name=i loop=$results}}
<strong><a href="/search/{{$results[i]|urlencode}}">{{$results[i]|validate}}</a></strong>
{{if $smarty.section.i.iteration % $divis == 0}}
</ul><ul class="col">