Freemarker default if NULL

I am using Freemarker 2.3.20 with JDK 7.

When I define a value in my template that results in NULL at runtime it gives me an error. I understand that there are many ways to deal with this error, as pointed out in answers like this: Simulate null parameters in Freemarker macros

But I want a global solution. My freemarker template has "hundreds" of fields that can be empty at any time. Instead of writing a function to be called to handle NULL, or setting the default to null with an exclamation point "!" Etc.; Is there a way to define something global in freemarker configs or overwrite some java class so that: all empty fields return "NULL" or a user-defined user-defined value.

+3


source to share


1 answer


You can add <#setting classic_compatible=true>

to .ftl file or add

Configuration cfg = new Configuration(); cfg.setClassicCompatible(true);

      



in your code.

+3


source