How to Loop Through a List of Objects in FreeMarker

FreeMarker is a template engine, meaning that it is a tool that creates text output. It is meant to be used with the Java programming language, especially with Model View Controller applications. The Model View Controller separates the program logic, interface and data of a website. FreeMarker allows interface designers to make changes without requiring the program logic portion to change. If you are new to FreeMarker, you can get up to speed pretty quickly by learning how to iterate through a list of objects.

Things You'll Need

  • FreeMarker (see Resource)
Show More

Instructions

    • 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>

Related Searches:

References

Resources

Comments

Related Ads

Featured