Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freemarker nested list

this works fine:

<#list myObjects as myObject>
  <tr>
    <td>${myObject.person.surname}</td>
    <td>${myObject.myListOfCountries[0].city.name}</td>
  </tr>
</#list> 

However if I instead try to create a nested list like so, which does not work :

<#list myObjects as myObject>
  <tr>
    <td>${myObject.person.surname}</td>
    <#list myObject.myListOfCountries as item>
       <td>${item.city.name</td>
    </#list> 
  </tr>
</#list> 

the error I receive is shown below :

freemarker.core.ParseException: Encountered "/"

Any ideas what causes the error - are nested lists allowed in freemarker ?

like image 745
NimChimpsky Avatar asked Apr 30 '12 16:04

NimChimpsky


People also ask

How do you create a list on FreeMarker?

FreeMarker doesn't support modifying collections. But if you really want to do this in FreeMarker (as opposed to in Java), you can use sequence concatenation: <#assign myList = myList + [newItem]> . Here you create a new sequence that wraps the two other sequences.

Does FreeMarker have content?

The has_content FunctionFreeMarker has built-in functions to detect for variables. The most common method of detecting for empty or null values uses the has_content function and the trim function. The has_content function is often used with another built-in FreeMarker function to detect for null values.

What are macros in FreeMarker?

Macro variable stores a template fragment (called macro definition body) that can be used as user-defined directive. The variable also stores the name of allowed parameters to the user-defined directive.


1 Answers

You haven't closed your brace. It should be:

<td>${item.city.name}</td>
like image 173
dogbane Avatar answered Oct 09 '22 08:10

dogbane