Search code examples
grailsgroovygsp

grails for each


I am trying to use groovy to create a list of items that is three items across and n number of items down. right now, my script is just one item across and n items down. here is what i have so far:

<g:each in="${Friends}" status="i" var="Friends">  
    <div style="position:relative; border:1px solid red; height:150px;width:150px">
       <img src=${Friends[3]} ><br>${Friends[1]} <br>${Friends[2]} <br>
       <input type="checkbox" name="email" value=${Friends[0]} />  
       <input type="hidden" name="fname" value=${Friends[1]}>                       
    </div>          
</g:each>

So, for each item in ${Friends}, I want to display it on the web page but i want it to be displayed in a grid that is three items across and n/3 items down.

thanks for your help jason


Solution

  • If I understand you correctly, just add the equivalent of

    if i % 3 == 0 { print a <br/> }
    

    as the first statement in your loop.