Reputation: 1593
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> Academic</li>
<li> Administrative</li>
<li> Bank</li>
<li> BPO</li>
<li> Civil</li>
<li> Defence</li>
</ol>
</div>
<div class="left1">
<ol>
<li> Engineering</li>
<li> Finance</li>
<li> Government</li>
<li> Hospitality</li>
<li> HR</li>
<li> 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
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