When I loop through a list in freemarker like below, it works fine.
<#list cModel.products as product>
But when I'm tring to assign the size of the list to a variable like,
<#assign totalProducts = cModel.products.getList()?size>
I'm getting an exception from free marker like below
left-hand operand: Expected a hash, but this evaluated to a sequence
Any suggestions?
I Hope you've accessing it wrongly.
As per your example, the list name is product. So,
<#assign totalProducts = cModel.getProducts()?size>
Should return back the size of the products.
Hope it helps.
Having json:
{
"domain": {
"kingdom": []
},
}
We create a variable and assign the size of the kingdom list to it.
<#assign kingdomLen = domain.kingdom?size>
<#if kingdomLen > 0 >
We have kingdoms!
</#if>
And that is how we use it in an if-example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With