Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails each tag with iteration

Hey. How can i have a variable in each tag to be an iterator (for example, first time run cycle takes value=1, second time value=2, and so on..

like image 465
andré_resende Avatar asked May 24 '11 17:05

andré_resende


1 Answers

The status attribute is what you are looking for. See below:

<g:each collection=${books} var="abook" status="i">
    ${i}
</g:each>

if you call ${i} inside the each tag it will return the current iteration count.

Assuming the books collection contains 5 books, the output will be:

0
1
2
3
4
like image 134
gotomanners Avatar answered Sep 18 '22 12:09

gotomanners