Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

step attribute in {section} creating unexpected results

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
rubyaryat
Smarty Rookie


Joined: 24 Apr 2003
Posts: 6

PostPosted: Sun May 04, 2003 4:00 pm    Post subject: step attribute in {section} creating unexpected results Reply with quote

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
Shocked

<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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 4:33 pm    Post subject: Reply with quote

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 Wink At least while there is no math in the engine...
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 6:01 pm    Post subject: Reply with quote

hmmm. Actually, this one does it in n iterations... but still an inner loop Sad

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun May 04, 2003 7:31 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 7:35 pm    Post subject: Reply with quote

@messju: that's the best one yet!!
Back to top
View user's profile Send private message
kasper
Smarty n00b


Joined: 24 Apr 2003
Posts: 4

PostPosted: Tue May 27, 2003 9:33 pm    Post subject: Reply with quote

thanx messju, it helped me !
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP