[Play20] nesting expressions in template

112 views
Skip to first unread message

ido

unread,
Feb 7, 2012, 11:55:33 AM2/7/12
to play-framework
I am trying to nest scala calls in a template, but fail:
I even tried putting some of the function in its own template but
still failed.
I am tring to put 10 items in a row, if its a None at this index,
empty td
I also miss an explanation for $@ notation in the wiki for templating.

case class Item1(map: Map[Int,String]) {
def item(index: Int): Option[String] = map.get(index)
}
-------
"expected start of definition" (at (index).map))
@(items: Seq[Item1])
items.map{ row =>
<tr>
@{(1 to 10).map{ index =>
@row.item(index).map(s => <td>@s</td>).getOrElse(<td></
td>)
}}
</tr>
}
------
"identifier expected but { found"
@(items: Seq[Item1])
items.map{ row =>
<tr>
@{(1 to 10).map{ index =>
@{row.item(index).map(s => <td>s</td>).getOrElse(<td></td>)}
}}
</tr>
}

-----
not found: value row
@(items: Seq[Item1])
items.map{ row =>
<tr>
@{(1 to 10).map{ index =>
row.item(index).map(s => <td>s</td>).getOrElse(<td></td>)
}}
</tr>
}
-----
"expected start of definition" }}
@(items: Seq[Item1])
@display(item: Item1, index: Int){
@item.item(index).map(s => <td>s</td>).getOrElse(<td></td>)
}
items.map{ row =>
<tr>
@{(1 to 10).map{ index =>
@display(row, index)
}}
</tr>
}
-----
same result with simple template


Guillaume Bort

unread,
Feb 7, 2012, 12:18:48 PM2/7/12
to play-fr...@googlegroups.com
@items.map { row =>
<tr>
  @using(1 to 10).map { index =>

    @row.item(index).map(s => <td>@s</td>).getOrElse(<td></
     }
   </tr>
}

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

--
Guillaume Bort

ido

unread,
Feb 7, 2012, 1:07:53 PM2/7/12
to play-framework
Thank you very much for the quick reply.

I forgot the @items!
And the @using is also interesting (and undocumented).

best,
ido
Reply all
Reply to author
Forward
0 new messages