View previous topic :: View next topic |
Author |
Message |
desr333 Smarty Rookie
Joined: 17 Apr 2003 Posts: 10 Location: California
|
Posted: Fri Apr 18, 2003 3:23 pm Post subject: cycle issue |
|
|
Hi all,
I don't know if this is a bug or feature I don't mean that in a bad way either, because this really could be useful in some cases.
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. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Apr 18, 2003 3:47 pm Post subject: |
|
|
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 |
|
desr333 Smarty Rookie
Joined: 17 Apr 2003 Posts: 10 Location: California
|
Posted: Fri Apr 18, 2003 3:58 pm Post subject: Thanks!!! |
|
|
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 |
|
desr333 Smarty Rookie
Joined: 17 Apr 2003 Posts: 10 Location: California
|
Posted: Fri Apr 18, 2003 4:26 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Apr 18, 2003 4:35 pm Post subject: |
|
|
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 |
|
desr333 Smarty Rookie
Joined: 17 Apr 2003 Posts: 10 Location: California
|
Posted: Fri Apr 18, 2003 4:57 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Apr 18, 2003 6:44 pm Post subject: |
|
|
you can tell cycle not to cycle. (schizophrenic, not ?)
{cycle value="..." reset=true advance=false}
greetings
messju |
|
Back to top |
|
desr333 Smarty Rookie
Joined: 17 Apr 2003 Posts: 10 Location: California
|
Posted: Fri Apr 18, 2003 6:54 pm Post subject: |
|
|
You are awesome! That works just the way I want it to! Thanks guys!!!!! |
|
Back to top |
|
Silex Smarty Rookie
Joined: 19 Apr 2003 Posts: 5 Location: In the rain
|
Posted: Sat Apr 19, 2003 11:19 pm Post subject: Add names to cycle |
|
|
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 |
|
Mister Internet Smarty Rookie
Joined: 21 Apr 2003 Posts: 9
|
Posted: Mon Apr 21, 2003 7:34 pm Post subject: |
|
|
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. |
|
Back to top |
|
risto Smarty Rookie
Joined: 26 Apr 2003 Posts: 21 Location: Norway
|
Posted: Tue Apr 29, 2003 11:48 pm Post subject: What about continuing the sycle outside a section? |
|
|
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 |
|
|