# Zebra striping using \<r:children:each\>?

**URL:** <https://www.ruby-forum.com/t/zebra-striping-using-reach/72550>\
**Category:** Radiant CMS\
**Created:** [October 18, 2006, 12:45am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550 "2006-10-18T00:45:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 12:45am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/1 "2006-10-18T00:45:11Z")

</div>

Kia ora all,

I was wondering what the easiest way to get zebra striping for  
\<r:children:each\> is?

In a rails app it would be:

\<%- for item in @items do -%\>  
\<tr class="\<%= cycle(“even”, “odd”) %\>"\>  
… use item …  
  
\<%- end -%\>

Any ideas 🙂

Regards  
Nathan

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 1:35am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/2 "2006-10-18T01:35:05Z")

</div>

Nathan Donaldson wrote:

> ```
> </tr>
> 
> ```
> 
> \<%- end -%\>
> 
> Any ideas 🙂

Sounds like a case for a custom tag or two. If you can come up with  
something nice, I’ll add it to the core.

–  
John

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 3:57am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/3 "2006-10-18T03:57:59Z")

</div>

Thanks John,

I’ve come up with something. Nice or not I’ll let you decide 🙂

Open to suggestions for changing names of tags.

It’s simplicity itself at the moment,

\<r:children:each order=“desc” reset\_cycle=“false”\> to carry on from the  
last row otherwise it will reset to zero so that the first row is “odd”

\<r:cycle\_row /\> to output “even” or “odd”

I hope this make sense and is useful to someone.

Regards  
Nathan

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 3:58am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/4 "2006-10-18T03:58:43Z")

</div>

Oops, tried to attach a file but got an application error. Where is the  
best place to send the plugin?

Regards  
Nathan

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 4:21am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/5 "2006-10-18T04:21:17Z")

</div>

Nathan Donaldson wrote:

> Oops, tried to attach a file but got an application error. Where is the  
> best place to send the plugin?

You could attach it to the ThirdPartyBehaviors page on the Radiant Wiki:

[http://dev.radiantcms.org/radiant/wiki/ThirdPartyBehaviors](http://dev.radiantcms.org/radiant/wiki/ThirdPartyBehaviors)

–  
John

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 4:25am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/6 "2006-10-18T04:25:18Z")

</div>

Nathan Donaldson wrote:

> I’ve come up with something. Nice or not I’ll let you decide 🙂
> 
> Open to suggestions for changing names of tags.
> 
> It’s simplicity itself at the moment,
> 
> \<r:children:each order=“desc” reset\_cycle=“false”\> to carry on from the  
> last row otherwise it will reset to zero so that the first row is “odd”
> 
> \<r:cycle\_row /\> to output “even” or “odd”

Perhaps it would be better to have two tags:

\<r:even\>…\</r:even\>  
\<r:odd\>…\</r:odd\>

which only render their contents when the index is even or odd? We  
should probably also add an \<r:index /\> tag that returns the number.

–  
John

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 4:46am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/7 "2006-10-18T04:46:32Z")

</div>

John W. Long wrote:

> Perhaps it would be better to have two tags:
> 
> \<r:even\>…\</r:even\>  
> \<r:odd\>…\</r:odd\>
> 
> which only render their contents when the index is even or odd? We  
> should probably also add an \<r:index /\> tag that returns the number.
> 
> –  
> John

Hi John,

I have added your suggestions and add it to the wiki page. You may have  
some ideas about how to better overload children:each

Regards  
Nathan

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 5:04pm UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/8 "2006-10-18T17:04:54Z")

</div>

John W. Long wrote:

> > \<r:cycle\_row /\> to output “even” or “odd”
> 
> Perhaps it would be better to have two tags:
> 
> \<r:even\>…\</r:even\>  
> \<r:odd\>…\</r:odd\>

Smarty allows you to cycle stuff while in a loop:

{section name=i loop=$items}

 {$items[i].field} {$items[i].field} ... {$items[i].field} {/section}

Type thing.

Regards  
–jm

> which only render their contents when the index is even or odd? We  
> should probably also add an \<r:index /\> tag that returns the number.
> 
> –  
> John

–  
Jacques Marneweck  
[http://www.powertrip.co.za/](http://www.powertrip.co.za/)  
[http://www.powertrip.co.za/blog/](http://www.powertrip.co.za/blog/)

#include \<std/disclaimer.h\>

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 6:33am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/9 "2006-10-18T06:33:28Z")

</div>

Nathan Donaldson wrote:

> I have added your suggestions and add it to the wiki page. You may have  
> some ideas about how to better overload children:each

Looks very nice! Thanks for packaging this up as a plugin. Do you have  
time to pull together a patch and ticket for it now?

–  
John

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 6:25pm UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/10 "2006-10-18T18:25:41Z")

</div>

> What if I wanted three colors? There’s got to be a generalized way to do  
> this, and one that doesn’t mangle r:children:each (which is complex  
> enough!). I’m thinking something like the way r:random works.

\<r:children:each\>  
\<r:circle mod=“2”\>…\</r:circle\>  
\</r:children:each\>

On 10/18/06, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Open to suggestions for changing names of tags.
> > 
> > ```
> > <td>{$items[i].field}</td>
> > 
> > ```
> > 
> > * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site:  
> [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Alexander H.  
[http://www2.truman.edu/~ah428](http://www2.truman.edu/~ah428)

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 25, 2006, 5:32am UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/11 "2006-10-25T05:32:55Z")

</div>

Hi All,

Just had time to get back to this.

John: For the patch, would you like me to create a patch so that the  
plugin works, or shifting all of the functionality into page\_context.rb?

Alexander and Sean: Sounds like an interesting idea, but maybe it’s  
better to keep it simple. I certainly don’t have a use for that type of  
funftionality, but would be interested to hear if someone does.

Regards  
Nathan

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 18, 2006, 5:57pm UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/12 "2006-10-18T17:57:34Z")

</div>

What if I wanted three colors? There’s got to be a generalized way to  
do  
this, and one that doesn’t mangle r:children:each (which is complex  
enough!). I’m thinking something like the way r:random works.

I’ll take a look at your code. I’m pretty busy today, but I may have a  
“How  
To” up my sleeve for this one.

Sean C.  
[seancribbs.com](http://seancribbs.com) – comments on my site are down because I was too lazy to  
get  
Akismet before it was too late

---

<div class="post-metadata">

**Author:** ![straylight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@straylight](https://www.ruby-forum.com/u/straylight)\
**Post date:** [October 25, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/zebra-striping-using-reach/72550/13 "2006-10-25T18:04:08Z")

</div>

Nathan Donaldson wrote:

> John: For the patch, would you like me to create a patch so that the  
> plugin works, or shifting all of the functionality into page\_context.rb?

A patch against page\_context.rb would be excellent. Let’s go with the  
even/odd approach for now.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)
