Define a new #set modifier such that a variable is only set if it is not defined, like so:
#set($!foo = "bar")
If the '!' character proceeds the variable foo, then $foo will be set with the value of "bar" ONLY IF $foo is not defined (is not in the context). Otherwise if $foo is defined it will remain unchanged.