|
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 |
ciqala Smarty Rookie
Joined: 28 Apr 2003 Posts: 9
|
Posted: Tue Apr 29, 2003 8:44 pm Post subject: looping through <tr><td>< |
|
|
I have a table i want to populate from an array but i can't think how to do it.
Code: |
pseudo code:
<table>
{section name=loop id=$id}
<tr>
<td width="50%">{$var[loop]}</td>
<td width="50%">{$var[loop]}</td>
</tr>
{/section}
</table>
---------------------------
required output:
<table>
<tr>
<td width="50%">1</td>
<td width="50%">2</td>
</tr>
<tr>
<td width="50%">3</td>
<td width="50%">4</td>
</tr>
<tr>
<td width="50%">5</td>
<td width="50%">6</td>
</tr>
</table>
|
i'm sure this is the kind of thing i need but it has to increment the id variable twice per loop as you can see in the output.
any help is much appreciated
Last edited by ciqala on Wed May 05, 2010 10:41 pm; edited 1 time in total |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Tue Apr 29, 2003 9:31 pm Post subject: |
|
|
Have a look at {html_tables} of Smarty 2.5.0. Also search the Wiki for it. I think you'll find your answer there |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Apr 29, 2003 9:59 pm Post subject: |
|
|
{section} http://smarty.php.net/manual/en/language.function.section.php supports an step value:
{section name=loop id=$id step=2}
<tr>
<td width="50%">{$var[loop]}</td>
{math equation="x + 1" x=$loop assign=partner}
<td width="50%">{$var[partner]}</td>
</tr>
{/section} |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Apr 29, 2003 10:19 pm Post subject: |
|
|
I would avoid {math} calls, especially in section loops. It uses eval() which isn't so efficient.
Use the solution in the wiki, or {html_table} for simple loops.
Monte |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Apr 29, 2003 10:28 pm Post subject: |
|
|
OOPS. I didn't mean to post that message. I realized that it wouldn't work out well as I was writing it and I thought I aborted it. Sorry, please ignore. |
|
Back to top |
|
ciqala Smarty Rookie
Joined: 28 Apr 2003 Posts: 9
|
|
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
|