velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Revusky <>
Subject Re: Indirect references
Date Sun, 10 Aug 2003 00:04:27 GMT
Claude Brisson wrote:

> This has been discussed not long ago, see
> In a nutshell, "$$" is not implemented, some folks (including me) think it should, others
think it should not... and the most common
> workaround is to explicitely call generic getters from the VTL.
> For your example, you need to place a reference to the context inside itself with :
> [java] context.put("context",context)
> and then do :
> [VTL] #set($list = $context.get("$listname"))

Actually, that trick only works if $listname is directly the name of a 
variable. It wouldn't work in the more fully general case, where it's a 
more complex expression.

#set ($exp = "foo")

$context.get("$exp") ==> returns the same thing as $foo

OTOH, if the expression is compound, as in:

#set ($exp = "")

then that won't work.

Well, not to disappoint people... they figure I'm going to point out 
that this feature is available in FreeMarker. Actually, almost. Somebody 
requested something like this just a few days ago and it is implemented. 
It's currently in CVS and will be in the very next FM release. It works 
like this:

<#assign exp = "">


would output the exact same thing as:


with the caveat that it's much less efficient, naturally, since it 
involves reparsing the expression each time it's evaluated. But 
sometimes people need this, I guess.


Jonathan Revusky
lead developer, FreeMarker project,
FreeMarker-Velocity comparison page,

View raw message