|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
GeXus Smarty Rookie
Joined: 16 Aug 2006 Posts: 28
|
Posted: Mon Jan 29, 2007 5:32 am Post subject: How to loop this array with section tags |
|
|
Code: |
Array ( [Automotive] => Array ( [0] => Array ( [sub_id] => [cat_id] => 37 [sub_name] => ) ) [Business] => Array ( [0] => Array ( [sub_id] => 27 [cat_id] => 51 [sub_name] => Services ) )
|
I have a bunch of data setup in this format, I'm currently using the foreach statement below to go through it
Code: |
{foreach from=$categories key='cat_name' item='category'}
{$cat_name}:
{foreach from=$category item='sub_category'}
{$sub_category.sub_name}
{/foreach}
{/foreach}
|
Does anyone know how I would loop through this using section instead of foreach? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Jan 29, 2007 5:46 pm Post subject: |
|
|
You can't and why would you want to? Section tags require 0-based indexed arrays -- yours is associative. |
|
Back to top |
|
GeXus Smarty Rookie
Joined: 16 Aug 2006 Posts: 28
|
Posted: Mon Jan 29, 2007 8:10 pm Post subject: |
|
|
I want to display the data in 3x columns, I can't seem to figure out how I would do that with foreach. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
GeXus Smarty Rookie
Joined: 16 Aug 2006 Posts: 28
|
Posted: Wed Jan 31, 2007 10:16 pm Post subject: |
|
|
Boots, I've looked at the thread but and I tried one option that seemed like it might work, where I had section tags within the first foreach, but it did not work and I was not using the iteration.. I'm really not sure what to do. I appreciate your help! |
|
Back to top |
|
GeXus Smarty Rookie
Joined: 16 Aug 2006 Posts: 28
|
Posted: Fri Feb 02, 2007 9:57 pm Post subject: |
|
|
Got it to work, for the record this is what I did
Code: |
{foreach from=$categories key='cat_name' item='category' name='cats'}
{if $smarty.foreach.cats.iteration % 3 == 1}
<td>
{$cat_name}:
{foreach from=$category item='sub_category'}
{$sub_category.sub_name}
{/foreach}
</td>
{/if}
{if $smarty.foreach.cats.iteration % 3 == 2}
<td>
{$cat_name}:
{foreach from=$category item='sub_category'}
{$sub_category.sub_name}
{/foreach}
</td>
{/if}
{if $smarty.foreach.cats.iteration % 3 == 0}
<td>
{$cat_name}:
{foreach from=$category item='sub_category'}
{$sub_category.sub_name}
{/foreach}
</td>
</tr>
<tr>
{/if}
{/foreach}
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|