FreeMarker error: left operand: a hash is expected, but this is evaluated in sequence

When I browse the list in freemarker as below, it works fine.

<#list cModel.products as product> 

But when I try to assign the size of the list to a variable, for example,

  <#assign totalProducts = cModel.products.getList()?size> 

I get an exception from a free marker as shown below

left operand: a hash is expected, but it is evaluated by the sequence

Any suggestions?

+8
source share
2 answers

I hope you make a mistake.

According to your example, the list name is a product. So,

 <#assign totalProducts = cModel.getProducts()?size> 

Must return the size of the products.

Hope this helps.

+11
source

Having JSON:

 { "domain": { "kingdom": [] }, } 

We create a variable and assign it the size of the kingdom list.

 <#assign kingdomLen = domain.kingdom?size> <#if kingdomLen > 0 > We have kingdoms! </#if> 

And that’s how we use it in the if example.

0
source

Source: https://habr.com/ru/post/972909/


All Articles