Velocity - Delete fields when can't be merged
-
12-09-2019 - |
Question
I use velocity to merge a String(template) with field like
hi there I'am ${name},
And I'am ${age} old.
velocity merged the field ${name}
and ${age}
with a kind of hashtable:
velocityEngine.evaluate(context, writer, "", template);
context
is the hashtable(or better a VelocityContext
type)
I want when Velocity can't find the field in the context he just delete them.
can i do this with a property or something?
Solution
Not sure if it is what you are asking, but if you want to prevent unassigned template vars from showing up in merged templates, you can use quiet notation by writing $!{name}
, there is also a global setting for that.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow