php - Smarty, new row every 4 iteration -


how can set in smarty every 4 iteration in loop, i'll new row in table? i'm trying this:

<table>     {foreach $arr $v}        {counter start=0}        {if $counter/4 == 0}            <tr><td>{$v}</td></tr>        {else}            <td>{$v}</td>        {/if}        <td>     {/foreach} </table> 

but understand it's idiotic, i'm stuck, there normal way that?

if can live empty row if there no data, use this:

{assign var="counter" value="0"} <table>     <tr>     {foreach $arr $v}        {assign var="counter" value=$counter + 1}        {if $counter % 4 == 0}            </tr><tr>        {/if}        <td>{$v}</td>     {/foreach}     </tr> </table> 

if can't live this, need check if there data available before rendering table.

it remains count of $arr must multiple of 4. otherwise columnspan attribute required set properly.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -