I can't find anything related to this on any question, and it is something really basic, but I can't figure it out.
So my problem is that I don't know how to set null to a variable in freemarker. Example:
${hi!"bye"} <#-- Prints "bye" because hi is undefined -->
<#assign hi="hi"> <#-- Sets a value to the var hi -->
${hi!"bye"} <#-- Prints "hi" because hi has a value -->
<#assign hi=null> <#-- This does not work but is what I am looking for -->
${hi!"bye"} <#-- I want it to print "bye" because hi should be undefined -->
I have this problem because I iterate over a list and set a var if some logic to the specific item validates, and then check if the var exists, but if the first item creates the var, then I will have the var set for the rest of the items in the list.
No, there's no "unassign", nor the concept of null
exists in FreeMarker (until 2.4.0 at least, but that's far away anyway). It only have missing variables (maybe technically a null
, maybe doesn't exist at all) and those that are there. I don't really get why is that needed in your case. Can you show a simplified example of the situation?