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

cycle issue

 
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 -> Bugs
View previous topic :: View next topic  
Author Message
desr333
Smarty Rookie


Joined: 17 Apr 2003
Posts: 10
Location: California

PostPosted: Fri Apr 18, 2003 3:23 pm    Post subject: cycle issue Reply with quote

Hi all,

I don't know if this is a bug or feature Laughing I don't mean that in a bad way either, because this really could be useful in some cases. Smile

I'm trying to use cycle to display different row colors in a table, then end the table and have another table do the same thing further down the page (using the same colors) in the same template. The problem is, the cycle function seems to remember where it left off, and in the second table it starts off with whatever color goes after the last color used in the last table (with cycle) What I was trying to do is have 2 separate tables, each starting with a light grey bg and then alternating with a darker grey. The problem comes when in the first table the last color is the light grey, then in the next table even though I start a new loop and use a new cycle, it continues with the dark grey instead of starting with the light one I specify. This only happens when I use the same colors in the cycle function on the same template. I hope this makes sense. Here's an example I simplified a bit for easier reading:

<table>
{section name=i loop=$aData}
<tr bgcolor="{cycle values="#eeeeee,#cccccc"}">
<td>{$aData[i]}</a></td>
</tr>
{/section}
</table>
<h1>another list</h1>
<table>
{section name=j loop=$aData2}
<tr bgcolor="{cycle values="#eeeeee,#cccccc"}">
<td>{$aData2[j]}</a></td>
</tr>
{/section}
</table>

Any help or advice would be much appreciated. The funny thing is, I can see where this would be useful in certain situations where you'd want to continue the cycle, which is why I said I wasn't sure if this was a bug or a feature. Smile
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Apr 18, 2003 3:47 pm    Post subject: Reply with quote

uff, you are right. the reset-attribute is missing in
the docs. i will add it soon.

do:
{cycle values="#eeeeee,#cccccc" reset=true}

and if you want to nest your cycles in nested section
give them uniq names.

have fun
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
desr333
Smarty Rookie


Joined: 17 Apr 2003
Posts: 10
Location: California

PostPosted: Fri Apr 18, 2003 3:58 pm    Post subject: Thanks!!! Reply with quote

Oh, great! Thanks so much. This means I could use it either way if I want. I can continue the cycle or start it over, awesome, Thanks!!!

edited post:Please see my next post


Last edited by desr333 on Fri Apr 18, 2003 4:27 pm; edited 1 time in total
Back to top
View user's profile Send private message
desr333
Smarty Rookie


Joined: 17 Apr 2003
Posts: 10
Location: California

PostPosted: Fri Apr 18, 2003 4:26 pm    Post subject: Reply with quote

Maybe I'm doing something wrong, but when I changed it to
{cycle values="#eeeeee,#cccccc" reset=true}

I just get the first color for every row. Maybe I'm doing something wrong, any ideas?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Apr 18, 2003 4:35 pm    Post subject: Reply with quote

That is because it resets every time. You need to call the reset once outside the loop.

Code:

{cycle ... print=false reset=true}
{section ...}
   {cycle ...}
{/section}


Monte
Back to top
View user's profile Send private message Visit poster's website
desr333
Smarty Rookie


Joined: 17 Apr 2003
Posts: 10
Location: California

PostPosted: Fri Apr 18, 2003 4:57 pm    Post subject: Reply with quote

That makes sense, I didn't even think of that.

One more problem though, when I place it outside the loop, and use the print=false, I think that's taking up the first value, so then in the loop it still starts with the second one. I guess I could just switch the values in the values=, and that should work with the second one always being the first after a reset.

Does that make sense? Sorry, I know I'm totally taking up time for such a small issue.
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Apr 18, 2003 6:44 pm    Post subject: Reply with quote

you can tell cycle not to cycle. (schizophrenic, not ?)

{cycle value="..." reset=true advance=false} Smile

greetings
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
desr333
Smarty Rookie


Joined: 17 Apr 2003
Posts: 10
Location: California

PostPosted: Fri Apr 18, 2003 6:54 pm    Post subject: Reply with quote

Laughing You are awesome! That works just the way I want it to! Thanks guys!!!!!
Back to top
View user's profile Send private message
Silex
Smarty Rookie


Joined: 19 Apr 2003
Posts: 5
Location: In the rain

PostPosted: Sat Apr 19, 2003 11:19 pm    Post subject: Add names to cycle Reply with quote

Could you not add names to cycle. Because what if someone wants to cycle one, start a new, then leave off where the first cycle was. Give it a name attribute and you have made it easier.
_________________
Life is like licking honey off a thorn
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Mister Internet
Smarty Rookie


Joined: 21 Apr 2003
Posts: 9

PostPosted: Mon Apr 21, 2003 7:34 pm    Post subject: Reply with quote

Silex,

that's pretty much what I did... I had this exact same issue, and I just did this:

{cycle values="plainrow,shadedrow" name="cycle1"}

... further on down the page in a completely separate table:

{cycle values="plainrow,shadedrow" name="cycle2"}

and it works exactly the same... the docs only recommend this syntax for nesting cycles, but I found it did exactly what I needed. Smile
Back to top
View user's profile Send private message
risto
Smarty Rookie


Joined: 26 Apr 2003
Posts: 21
Location: Norway

PostPosted: Tue Apr 29, 2003 11:48 pm    Post subject: What about continuing the sycle outside a section? Reply with quote

Code:

{cycle values="OddRow,EvenRow" assign="row_class"}
{section}
    {$row_class} {$row_class}     //both the same this is what i wont
{/section}

{$row_class}   


How can I here continue the cycle???
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 -> Bugs 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