Search code examples
freemarker

While loop in Freemarker


How do I create a similar loop in Freemarker(FTL) In freemarker I have this statement:

<#if myVariable?? >
  // do stuff
</#if>

and I want to convert it to a while loop is it possible?

Javascript-code I want to replicate

while (myVariable != null) {
  // do stuff
}

If not possible how is the recursive approach in Freemarker?


Solution

  • The template language only supports looping via #list. So if you need to do that kind of loop, the a workaround is this:

    <#list 0..1000000000 as _>
      <#if exitCondition><#break></#if>
      ...
    </#list>