Search code examples
phpapachesmarty

4 columns in smarty


Is this even on the same planet as the correct code format in smarty.

   {foreach from=$watchvendor item=item}            
   <td><a href="{$vendorUrl}?vid={$item.id}">{$item.id} - {$item.nick}</a></td>
   {math equation= 'x/y' x=$item y='4' assign='howmany'}
   {if $howmany eq 0}
   </tr>
   <tr>
   {/if}      
  {/foreach}

i assume that $item is the element identity in the array ie.. 0 1 2 3 4 5 so when that did not work i tried this as well

{math equation=" 'x/y' x=count($watchvendor) y='4' assign='howmany'}

so basically if the loop divided by 4 = 0 its time for a new row.

The basic code without the extra math works fine i just want it spread out on the page.

ok i used

{$item|@debug_print_var}

and got this

Array (2)
  id => 8
  nick => "bbuddy" Array (2)
  id => 7
  nick => "span" Array (2)
  id => 6
  nick => "LJ" Array (2)
  id => 5
  nick => "JD" Array (2)
  id => 4
  nick => "Jsmith159"

sure is a strange looking array, first time i have ever seen a smarty array - no element id's


Solution

  • This seems to work...

      <table class="ow_table_1 ow_form ow_automargin">
      <tr> 
       {assign var=cnt value=0}      
       {foreach from=$watchvendor item=item}
       {assign var=cnt value=$cnt+1}                        
       <td><a href="{$vendorUrl}?vid={$item}">{$item.id} - {$item.nick}</a></td>
       {if $cnt eq 4}
       </tr>
       <tr>
       {assign var=cnt value=0}
       {/if}
       {/foreach}
      </tr>
    </table>