Mike Austin's Blog

Monday, February 16, 2009

Getting around no "status" in Grails

In Grails, there is a handy "collection" attribute to <g:render> when rendering templates, but there is no way to pass a "status" attribute to get the current index. This is useful for zebra striping for example.

An approach I've been using is not to use "collection", and do the iteration in the template. If you want to render only one, you can just pass a list of one element.

comment.gsp
<g:render template="comments" model="[comments: comments]"/>
commentDetails.gsp
<g:render template="comments" model="[comments: [comment]]"/>
_comments.gsp
<g:each var="comment" in="${comments}" status="index">
${comment.message}
</g:each>

0 Comments:

Post a Comment

<< Home