In FreeMarker, foo.bar is the same as foo["bar"], but inside the [] you can have an arbitrary expression that evaluates to a string. So the expression you are looking for is simply foo[var].
BTW, what your macro tries to do is just ${foo[var]!bar[var]}