|
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 |
LordNeon Smarty Rookie
Joined: 01 Dec 2005 Posts: 13 Location: Oslo, Norway
|
Posted: Thu Dec 01, 2005 11:14 am Post subject: A {cycle} tip |
|
|
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 |
|
jet-jock Smarty Regular
Joined: 11 Sep 2003 Posts: 48 Location: Connecticut, USA
|
Posted: Mon Dec 19, 2005 2:00 am Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Dec 19, 2005 2:03 am Post subject: |
|
|
Or use CSS classes:
Code: | <tr class="{cycle values="normal,hover"}"><td>My Content</td></tr> |
|
|
Back to top |
|
LordNeon Smarty Rookie
Joined: 01 Dec 2005 Posts: 13 Location: Oslo, Norway
|
Posted: Thu Dec 22, 2005 1:29 pm Post subject: |
|
|
boots wrote: | Or use CSS classes:
Code: | <tr class="{cycle values="normal,hover"}"><td>My Content</td></tr> |
|
Havn't thought of that.
Thanks! _________________ That's how we Troll |
|
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
|