Here's another approach that I used in a small project recently...
I wrote a small stateful utility class,
class OddOrEven {
private var isEven = true
def getAndToggle: String = {
val s = toString
isEven = (!isEven)
s
}
override def toString = if (isEven) "even" else "odd"
}
and I use it as such,
val oddOrEven = new OddOrEven
for (row <- rows) yield {
<tr class={oddOrEven.getAndToggle}>
<td> ... </td>
</tr>
}
But I generally prefer to put that presentation stuff in the CSS/Javascript
directly instead of in the code.
alex
On Mon, May 11, 2009 at 6:54 AM, marius d. <[email protected]> wrote:
>
> Assume that in your snippet you have a List[String] that you want to
> render as table rows such as:
>
>
> val list = "one" :: "two" :: "three" :: Nil
>
> def render(xhtml: NodeSeq): NodeSeq = {
> <table>{
> list.zipWithIndex((e, idx) => <tr><td>{e}</td></tr> %
> if (idx % 2 == 0)
> Null // Null is a MetaData here
> else
> ("class" -> "my_gray_out")
> )
> }</table>
> }
>
> note that i did not test the code ... so it may not compile ... but I
> hope you got the idea.
>
> Br's,
> marius
>
> On May 11, 3:52 pm, Magnus Alvestad <[email protected]> wrote:
> > I'm still learning lift (and scala). For my sample application I want
> > to display a table with alternating row colors. I want to put the
> > style in my CSS file and add a classname to every TR in my table to
> > indicate odd and even rows. However, I don't know how to take a value
> > from the snippet binding and assigning it to an attribute in my
> > template file. Can anyone point me in the right direction?
> >
> > -Magnus
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---