The archives are littered with snippets of wisdom that are not captured in the User or Developer guides. Find something that isn't in the manual, and folks ask a lot on the list? Please, add it here. Eventually, the info may move into the offical guides. If you have a specific question that is not answered here or in the mailing list archives, then ask please the user list.

Velocity

  #set($bar = 'name')
  #set($var = '$foo') ## a string in single quotes is not interpolated
  #evaluate("${var}.$bar")

You can also check the RenderTool or ViewRenderTool in VelocityTools, which offers some flexibility on which context to use in the evaluation, or write a custom tool using Velocity.evaluate(...).

Here is a solution provided by Shinobu Kawai:

#foreach($key in $myMap.keySet())
 #set($value = $myMap.get($key))
 $key = $value
#end

or you can do

#foreach($entry in $myMap.entrySet())
 $entry.key = $entry.value
#end
#if ($car.fuel == null)

If none of these tweaks work for you here are a few more tips:

Remember, Velocity doesn't compile your templates. They are parsed into an AST (abstract syntax tree) and that is what gets cached. So, reducing template complexity will shrink the tree and produce immediate memory savings. For loops and (java) "tools" are simpler than velocimacros. (Nathan Bubna & Bruno Carle)

Velocity Tools

DVSL & Anakia & Texen & Misc