AssamGuy
AssamGuy

Reputation: 1593

Make array results in different divs in smarty

I am using smarty as my template engine . I have a php result assigned to smarty $sac . If I am writing

{foreach name = feach item = k from = $sac}
    {$k->job_category}    
{/foreach}

it shows the result in a line . But our designer used different divs to show the result .

<div class="left1">

<ol>
<li>&nbsp;  Academic</li>
<li>&nbsp;  Administrative</li>
<li>&nbsp;  Bank</li>
<li>&nbsp;  BPO</li>
<li>&nbsp;  Civil</li>
<li>&nbsp;  Defence</li>
</ol>
</div>

<div class="left1">

<ol>
<li>&nbsp;  Engineering</li>
<li>&nbsp;  Finance</li>
<li>&nbsp;  Government</li>
<li>&nbsp;  Hospitality</li>
<li>&nbsp;  HR</li>
<li>&nbsp;  Insurance</li>
</ol>
</div>

etc . Show I want to know how can I display results in this form . I think I can use modulus operator(%) since numer of fields are fixed in each column(6) .

Upvotes: 0

Views: 207

Answers (1)

sdemirkeser
sdemirkeser

Reputation: 440

you can use name iterator with forach. its based on loop foreach twice;

<div class="left1">
<ol>
{foreach name = feach item = k from = $sac name=cat}
    {if $smarty.foreach.cat.index%2==0}
        <li>{$k->job_category}</li>
    {/if}
{/foreach}
</ol>
</div>

and for the next div block

<div class="left1">
<ol>
{foreach name = feach item = k from = $sac name=cat}
    {if $smarty.foreach.cat.index%2!=0}
        <li>{$k->job_category}</li>
    {/if}
{/foreach}
</ol>
</div>

Upvotes: 1

Related Questions