API / Apache FreeMarker Interview questions
What are the types of loops available in FreeMarker?
The main looping construct is <#list sequence as item> ... </#list>, which iterates a sequence or the values of a hash.
<#list products as p> ${p?index + 1}. ${p.name} - ${p.price?string.currency} </#list>
Inside the loop body FreeMarker exposes loop variables such as p?index (or the older p_index form) for the position and p?has_next for whether more items follow, which is useful for printing separators. A hash can be looped the same way after converting it with ?keys or ?values, and the <#items as item> nested form can be used inside <#list sequence> when a separate <#sep> block is needed between items.
More Related questions...