For loop in velocity pages.

For loop in velocity pages.

This question has suggested answer(s)

Hi,

how do i display following data using for loop in velocity pages ?

<tr>

<td class="graybg"><input type="radio" name="selectDeal" checked/></td>

<td class="graybg">00003421</td>

<td class="graybg">12345</td>

<td class="graybg">67890</td>

<td class="graybg">80</td>

<td class="graybg">5</td>

<td class="graybg">2</td>

<td class="graybg"></td>

<td class="graybg"></td>

<td class="graybg"><textarea class="textarea2" onfocus="blur();">Here is my final quote</textarea></td>

</tr>

<tr>

<td class="graybg"><input type="radio" name="selectDeal" /></td>

<td class="graybg">00003422</td>

<td class="graybg">12345</td>

<td class="graybg">67890</td>

<td class="graybg">80</td>

<td class="graybg">5</td>

<td class="graybg">2</td>

<td class="graybg"></td>

<td class="graybg"></td>

<td class="graybg"><textarea class="textarea2" onfocus="blur();">Here is my final quote</textarea></td>

</tr>

 

this is the for loop i have come up with :

#foreach($i in $my)

<p>$i.toString()</p>

#end

All Replies
  • Not sure what you're asking.  Just put the table markup inside your foreach loop and reference your object properties where you want them to display.  As long as the type of your "$my" object supports iterating (It's some sort of List or Array) you should be fine.

    <table>

    #foreach($i in $my)

      <tr>

      <td>$i.PropertyName</td>

      <td>$i.Property1Name</td>

      </tr>

    #end

    </table>

  • In the case you strictly need a for loop rather than a foreach loop, Velocity supplies a shortcut for generating an array between two bounds 

    #foreach($i in [0..10])
    $i,
    #end