Handling null values in Freemarker

Anand B picture Anand B · Dec 19, 2012 · Viewed 135.8k times · Source

How to handle null values in Freemarker? I get some exceptions in the template when null values are present in data.

Answer

Arnaud picture Arnaud · Dec 23, 2014

Starting from freemarker 2.3.7, you can use this syntax :

${(object.attribute)!}

or, if you want display a default text when the attribute is null :

${(object.attribute)!"default text"}