Question

I need to iterate over projects, than over issues then over the attchments in order to list them. Is there a better way of achieving this? What I do: I get in the servlet the lists, than in pass them to the .vm template and I iterate over them. But I dont know if it is possible to have nested for loops in the templates:

 #foreach($i in $I)
<tr>
    <td>$i.getSmthing()</td>
    <td>
    <div id="list" class="listClass">
        <ul>
        <#foreach($a in $i.attchments)
            <li>$a.getSmthing</li>
         #end
         </div>
</tr>
#end
Was it helpful?

Solution

Yes it is possible. Velocity templating supports for-in-for. as a result:

#foreach($i in $I)
  #foreach($j in $J)
     <p>i.getAttr() j.getAttr();</p>
  #end
#end

PS in case you run into some problems, be sure your Velocity context contains actually what you want. (I failed because of that.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top