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

A {cycle} tip

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
LordNeon
Smarty Rookie


Joined: 01 Dec 2005
Posts: 13
Location: Oslo, Norway

PostPosted: Thu Dec 01, 2005 11:14 am    Post subject: A {cycle} tip Reply with quote

I wanted to autogenerate background colors for my talble rows and also have the table cell to display another color when hovering the mouse over the cells. After spending some time fooling around I finally got it working.
Here's what I did:

Code:

<table>
{foreach from=$some_array item=item key=key}
<tr bgcolor="{cycle name='normal' values='#CDCDCD, #FFFFFF'}" onMouseOver="this.bgColor='#AAAAAA'" onMouseOut="this.bgColor='{cycle name='hover' values='#CDCDCD, #FFFFFF'}'">
<td>{$item.some_cell}</td>
</tr>
{/foreach}
</table>


It didn't occure to me that I needed the name option to seperate the two cycle function.
I hope this will save someone's time.
_________________
That's how we Troll
Back to top
View user's profile Send private message MSN Messenger
jet-jock
Smarty Regular


Joined: 11 Sep 2003
Posts: 48
Location: Connecticut, USA

PostPosted: Mon Dec 19, 2005 2:00 am    Post subject: Reply with quote

Here's a follow on to that tip:

If you set your cycle values in your config file, you can change colors site wide by just editing one line:

myConfig.conf:

[php:1:10b48bf107]hover = "#FFFFEE,#FFFFDE"[/php:1:10b48bf107]

And use in your template file like this:

<tr bgcolor="{cycle name="hover" values=$smarty.config.hover}"><td>My Content</td></tr>

Jet-Jock
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Mon Dec 19, 2005 2:03 am    Post subject: Reply with quote

Or use CSS classes:

Code:
<tr class="{cycle values="normal,hover"}"><td>My Content</td></tr>
Back to top
View user's profile Send private message
LordNeon
Smarty Rookie


Joined: 01 Dec 2005
Posts: 13
Location: Oslo, Norway

PostPosted: Thu Dec 22, 2005 1:29 pm    Post subject: Reply with quote

boots wrote:
Or use CSS classes:

Code:
<tr class="{cycle values="normal,hover"}"><td>My Content</td></tr>


Havn't thought of that.

Thanks! Smile
_________________
That's how we Troll
Back to top
View user's profile Send private message MSN Messenger
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 -> Tips and Tricks 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