(Quick Reference)



Uses the Groovy JDK each method to iterate over each element of the specified object.


<g:each in="${books}">
    <p>Title: ${it.title}</p>
    <p>Author: ${it.author}</p>

With a named item:

<g:each var="book" in="${books}">
    <p>Title: ${book.title}</p>
    <p>Author: ${book.author}</p>

With a range literal - note how the literal must be enclosed in parentheses:

  <g:each var="i" in="${ (0..<100) }">
    <li>Item ${i}</li>

Another example, where a named item is necessary (otherwise the access to the title property will fail):

<g:each in="${itemList}" var="item">
    <g:link action="show" id="${item.id}">${item.title}</g:link>

Using the status parameter to alternate the coloring of a table's rows:

  <g:each status="i" in="${itemList}" var="item">
    <!-- Alternate CSS classes for the rows. -->
    <tr class="${ (i % 2) == 0 ? 'a' : 'b'}">



  1. in - The object to iterate over
  2. status (optional) - The name of a variable to store the iteration index in. Starts with 0 and increments for each iteration. If this parameter is used, then var is required.
  3. var (optional) - The name of the item, defaults to "it".

Note that var attribute must be specified when the iterator value is to be used from within the body of a GSP Dynamic Tag, such as in <g:link>.