Here are some requests for null support in Velocity. Here is the discussion about this on the developer list.
The word "null" should be treated as null in Velocity specific content
should make a 3 element list, with the elements "one", null and "three".
should call the "bar" method of the "foo" object with a null parameter.
- An unreferenced reference is treated as null, so
will do as the above.
The "if" directive should be able to compare references with null
if foo was not in the Context.
if foo was in the Context.
- Using IfNullDirective / IfNotNullDirective and will do as the above.
- Many others are listed at CheckingForNull.
The "set" directive should accept null value as the RHS.
Assuming that $bar wasn't in the Context,
should both remove "foo" from the Context, and
should both set the "foo" property of "$map" to null.
- Setting null by invoking Context#remove(), or setter methods with null. Assuming that the Context was $ctx,
- Using the NullTool / ViewNullTool. will do as the above. Note: NullTool can't set properties to null.
- Bugzilla #20999 contains a patch to give this behaviour.
- It is also stated in bugzilla that you can achieve this by using the EventCartridge, but I can't figure out how. I'm hoping somebody will post a code snipplet for us.
The "foreach" directive should set null when the element is null
Currently, it preserves the last element.
- Using the NullTool / ViewNullTool. will do as the above.
- Bugzilla #27741 contains a patch to give this behaviour.
null and the empty string should be totally equivalent
Comment from Nathan about the null keyword and the if directive support:
-0 i'm not totally against it, but i'm instinctively uncomfortable with using this programming concept in a template language. personally, i've always felt in a display-oriented language, null and the empty string should be totally equivalent. but that is already not the case, so i can't really be -1 on this.