How to Loop Through a List of Objects in FreeMarker
- 1). Create a new text document by opening a Text Edit program. Save the document as “tutorial.html.”
- 2). Write an HTML statement that outputs some helpful text that identifies the list of objects:
<p>Here are the cars we have for sale:
<ul> - 3). Write a FreeMarker directive that accesses the Data Model of the Model View Controller application. For example, if your Data Model has a list of objects named “cars” under the heading “dataModelCars,” you can loop through the entire list by writing the following FreeMarker directive:
<#list dataModelCars.cars as car>
<li>${car}
</#list>
<ul>
Source...