Skip to main content
Inspiring
August 14, 2007
Question

Help for a CF noob

  • August 14, 2007
  • 14 replies
  • 947 views
I want to write a toggle color switch into a CF page with a data table on it
something like this PHP -

<tr<? $toggle=!$toggle; echo($toggle?' class="even"':' class="odd"'; ?>>

What would that look like in CF?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



This topic has been closed for replies.

14 replies

Inspiring
August 14, 2007
There is no loop. It's a static data table. I need it all to be self
contained in a single statement.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Tom Muck" <tommuck@NO-SPAM-hotmail.com> wrote in message
news:f9strn$46a$1@forums.macromedia.com...
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:f9sptl$t2g$1@forums.macromedia.com...
>> There is no recordset. It's a static page in a curiously CF site (all to
>> only use cfincludes) that I have been asked to 'fix'. So - would it be -
>>
>> <tr class="#IIF(toggle/mod2, DE('odd'), DE('even'))#">#toggle = !toggle#
>
> Ah, you said "data table", which led me to believe there was data in it.
> :-)
>
> No, it would be:
>
> Initialize the toggle:
>
> <cfset toggle = 0>
>
> Inside the loop, increment it:
>
> <cfset toggle = toggle + 1>
>
> Then in the tag:
>
> <tr class="#IIF(toggle MOD 2, DE('odd'), DE('even'))#">
>
> Tom
>


Inspiring
August 14, 2007
.oO(Murray *ACE*)

>I just don't have the time or energy to manually add classes to hundreds of
>rows of existing tabular content on tens of pages - do you?

Yes, I would have the time, but there are much better and more pleasing
ways to spend it. ;-D

But I've never talked about adding those classes by hand. There should
be a way to automate it ... OK, it might require some thinking time ...

Hmm, it should be possible with regular expressions - you can match the
current and the following element, the replacement string would contain
the current element with the class addition and the unchanged following
element ... could work ... just thinking loudly ...

Micha
Inspiring
August 14, 2007

"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:f9sptl$t2g$1@forums.macromedia.com...
> There is no recordset. It's a static page in a curiously CF site (all to
> only use cfincludes) that I have been asked to 'fix'. So - would it be -
>
> <tr class="#IIF(toggle/mod2, DE('odd'), DE('even'))#">#toggle = !toggle#

Ah, you said "data table", which led me to believe there was data in it. :-)

No, it would be:

Initialize the toggle:

<cfset toggle = 0>

Inside the loop, increment it:

<cfset toggle = toggle + 1>

Then in the tag:

<tr class="#IIF(toggle MOD 2, DE('odd'), DE('even'))#">

Tom


Inspiring
August 14, 2007
There is no recordset. It's a static page in a curiously CF site (all to
only use cfincludes) that I have been asked to 'fix'. So - would it be -

<tr class="#IIF(toggle/mod2, DE('odd'), DE('even'))#">#toggle = !toggle#

?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Tom Muck" <tommuck@NO-SPAM-hotmail.com> wrote in message
news:f9sphs$sis$1@forums.macromedia.com...
> >I want to write a toggle color switch into a CF page with a data table on
> >it
>> something like this PHP -
>>
>> <tr<? $toggle=!$toggle; echo($toggle?' class="even"':' class="odd"'; ?>>
>>
>> What would that look like in CF?
>
> I'd use the current row of the recordset instead of setting another toggle
> variable in a data table:
>
> <tr class="#IIF(rs.CurrentRow MOD 2, DE('odd'), DE('even'))#">
>
> --
> Tom Muck, Adobe Community Expert
> Dreamweaver Extensions/Articles -- http://www.tom-muck.com/
> Cartweaver Development Team - http://www.cartweaver.com/
> Extending Knowledge Daily - http://www.communitymx.com/
>
>


Inspiring
August 14, 2007
>I want to write a toggle color switch into a CF page with a data table on
>it
> something like this PHP -
>
> <tr<? $toggle=!$toggle; echo($toggle?' class="even"':' class="odd"'; ?>>
>
> What would that look like in CF?

I'd use the current row of the recordset instead of setting another toggle
variable in a data table:

<tr class="#IIF(rs.CurrentRow MOD 2, DE('odd'), DE('even'))#">

--
Tom Muck, Adobe Community Expert
Dreamweaver Extensions/Articles -- http://www.tom-muck.com/
Cartweaver Development Team - http://www.cartweaver.com/
Extending Knowledge Daily - http://www.communitymx.com/


Inspiring
August 14, 2007
.oO(Murray *ACE*)

>That's cool. I may do that, then! Thankee....

Eh, not really ... if it's a static table you would be better off with
hard-coding the 'odd' and 'even' classes (although only one of them is
really necessary). Your posted code only makes sense in a loop, as Tom
pointed out.

Too bad CSS3 is still years away from being widely usable ...

Micha