Posts tagged: Smarty Tips

Solution for PHP Smarty three columns

Example 1 Create a three-column table. (Display x items in one colum. For example, list 50 US states in three columns, that is, 17, 17 and 16 in each column.) <table border='0' cellpadding='0' cellspacing='0'> <tr> <td width='33%'> <{foreach name=states from=$data.states key=key item=state}> <{capture name='column'}><{math equation="x % 17" x=$smarty.foreach.states.index}><{/capture}> <{if (($smarty.capture.column == "0" ) && (($smarty.foreach.states.index != "0" )))}> </td><td width='32%' align='left'> <{/if}> <a href="<{$rootDir}>state.php?pid=<{$}>"><{$}></a><br /> <{/foreach}> </td> </tr> </table> Example 2 Create a three-column table. (Display each item in a cell and there are 3x times items.) <table border="0" cellpadding="0" cellspacing="0"> <tr> {foreach name=products from=$products item=product key=key} {capture name="column"}{math equation="x % 3" x=$key}{/capture} {if ($smarty.capture.column == "0")} </tr><tr> {/if} <td width="33%" align="left"> {$} </td> {/foreach} </tr> </table>