Zebra striping using <r:children:each>?

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 :slight_smile:

Regards
Nathan

Nathan Donaldson wrote:

</tr>

<%- end -%>

Any ideas :slight_smile:

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

Thanks John,

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

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

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

Regards
Nathan

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


John

Nathan Donaldson wrote:

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

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

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

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/blog/

#include <std/disclaimer.h>

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

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. [email protected] wrote:

Open to suggestions for changing names of tags.

<td>{$items[i].field}</td>

Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:
http://lists.radiantcms.org/mailman/listinfo/radiant


Alexander H.
http://www2.truman.edu/~ah428

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

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 – comments on my site are down because I was too lazy to
get
Akismet before it was too late

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs