Search code examples
javafreemarker

How to update value before sorting in freemarker template


I have the following html template

[#list PRODUCTS?sort_by("Price_origin_type") as product]
[/#list] 

I've got the following exception

Exception while merging FreeMarker template with values - ?sort_by(...) failed at sequence index 2 (0-based): All key values in the sequence must be numbers, because the first key value was that. However, the key value of the current item isn't a number.

Is there a way to set 0 for empty values?


Solution

  • This doesn't replace empty values with zeros but should exclude them from the list:

    [#list PRODUCTS?filter(p -> p != "")?sort_by("Price_origin_type") as product]
    [/#list]