|
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 |
rubyaryat Smarty Rookie
Joined: 24 Apr 2003 Posts: 6
|
Posted: Sun May 04, 2003 4:00 pm Post subject: step attribute in {section} creating unexpected results |
|
|
I've been experimenting with index_prev, index and index_next to create a three column table.
What I want the following table to create is:
0 1 2
3 4 5
What I get is:
-2 1 4
1 4 7
<table>
{section name=oi loop=$orders_data1 start=1 step=3}
<tr>
<td width=252>
{$smarty.section.oi.index_prev}
</td>
<td width=252>
{$smarty.section.oi.index}
</td>
<td width=252>
{$smarty.section.oi.index_next}
</td>
</tr>
{/section}
</table>
I would have thought step would have incremented the index after every section iteration. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 4:33 pm Post subject: |
|
|
If you can live with an inner section...
Code: |
$smarty->assign('orders', array(1,2,3,4,5,6));
---
<table>
{section name=oi loop=$orders step=3}
<tr>
{section name=o loop=$orders start=$smarty.section.oi.index max=3}
<td width=252>
{$smarty.section.o.index}
</td>
{/section}
</tr>
{/section}
</table> |
0 1 2
3 4 5
The outer loop takes n/3 iterations while the inner loop takes n iterations -- in other words, this is best done in PHP where it can be done in n iterations At least while there is no math in the engine... |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 6:01 pm Post subject: |
|
|
hmmm. Actually, this one does it in n iterations... but still an inner loop
Code: | <table>
{section name=oi loop=$orders step=3}
<tr>
<td width=252>
{$smarty.section.oi.index}
</td>
{section name=o loop=$orders start=$smarty.section.oi.index max=2}
<td width=252>
{$smarty.section.o.index_next}
</td>
{/section}
</tr>
{/section} |
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun May 04, 2003 7:31 pm Post subject: |
|
|
Code: |
<table border=1>
{section name=oi loop=$orders_data1}
{if $smarty.section.oi.index % 3 == 0}<tr>{/if}
<td width=252>
{$smarty.section.oi.index}
</td>
{if $smarty.section.oi.index % 3 == 2}</tr>{/if}
{/section}
</table>
|
for all cases see:
http://smarty.php.net/contribs/examples/dynamic_table_columns/table.tpl.txt
have fun
messju |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 7:35 pm Post subject: |
|
|
@messju: that's the best one yet!! |
|
Back to top |
|
kasper Smarty n00b
Joined: 24 Apr 2003 Posts: 4
|
Posted: Tue May 27, 2003 9:33 pm Post subject: |
|
|
thanx messju, it helped me ! |
|
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
|