|
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 |
prashant_balan Smarty n00b
Joined: 31 Oct 2011 Posts: 1
|
Posted: Mon Oct 31, 2011 7:55 am Post subject: How to make the foreach loop iteration generate rows? |
|
|
Hi,
I am trying to use Smarty foreach loop to generate a table from an array.. How can I make it show the following output?
Array : {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,.....}
output required:
<table>
<tr>
<td> 1 </td><td> 2 </td><td> 3 </td><td> 4 </td><td> 5 </td>
</tr>
<tr>
<td> 6 </td><td> 7 </td><td> 8 </td><td> 9 </td><td> 10 </td>
</tr>
<tr>
<td> 11 </td><td> 12 </td><td> 13 </td><td> 14 </td><td> 15 </td>
</tr>
....
<tr>
</tr>
</table>
Please help..
Thanks in advance! |
|
Back to top |
|
letsface_coder Smarty n00b
Joined: 31 Oct 2011 Posts: 1
|
Posted: Mon Oct 31, 2011 8:42 am Post subject: Re: How to make the foreach loop iteration generate rows? |
|
|
prashant_balan wrote: | Hi,
I am trying to use Smarty foreach loop to generate a table from an array.. How can I make it show the following output?
Array : {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,.....}
output required:
<table>
<tr>
<td> 1 </td><td> 2 </td><td> 3 </td><td> 4 </td><td> 5 </td>
</tr>
<tr>
<td> 6 </td><td> 7 </td><td> 8 </td><td> 9 </td><td> 10 </td>
</tr>
<tr>
<td> 11 </td><td> 12 </td><td> 13 </td><td> 14 </td><td> 15 </td>
</tr>
....
<tr>
</tr>
</table>
Please help..
Thanks in advance! |
Hi there!
you could use:
({foreach name=disp from=$array item=item})
({if $smarty.foreach.disp.iteration %5== 0})
<tr>
</tr>
({elseif})
<td>
({$item})
</td>
({/if})
({/foreach})
Thats pretty much it!
Enjoy! |
|
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
|