Each Grails Tag Iterated

Hey. How can I have a variable in each tag as an iterator (for example, the first run loop takes value = 1, the second time value = 2, etc.

+5
source share
1 answer

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 each tag, it will return the current iteration counter.

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

0
1
2
3
4
+10
source

All Articles