You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Tim Colson <tc...@cisco.com> on 2002/05/08 02:26:58 UTC

Dynamically resolved Reference Names

I expect to be flogged for this but I can't find it in the archives or
manual, so here goes.

Imagine a Constants.java with a static String FOO_NAME="proper_foo"
Imagine a velocity context, ctx, setup like so:
 ctx.put(FOO_NAME, FOO_NAME); // $FOO_NAME will be "proper_foo"
 ctx.put("proper_foo", "42");

Is it possible to create a template.vm that outputs '42' without
actually typing $proper_foo ?
  I.e. something along the lines of ${$FOO_NAME} 

(Please don't ask me why I don't want to type $proper_foo - I don't have
a good answer ;-)

See, I told you I was expeting a flogging. 

Thanks,
Tim





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamically resolved Reference Names

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 5/7/02 8:26 PM, "Tim Colson" <tc...@cisco.com> wrote:

> I expect to be flogged for this but I can't find it in the archives or
> manual, so here goes.
> 
> Imagine a Constants.java with a static String FOO_NAME="proper_foo"
> Imagine a velocity context, ctx, setup like so:
> ctx.put(FOO_NAME, FOO_NAME); // $FOO_NAME will be "proper_foo"

 ctx.put("FOO_NAME", FOO_NAME); // $FOO_NAME will be "proper_foo"


> ctx.put("proper_foo", "42");
> 
> Is it possible to create a template.vm that outputs '42' without
> actually typing $proper_foo ?
> I.e. something along the lines of ${$FOO_NAME}
> 
> (Please don't ask me why I don't want to type $proper_foo - I don't have
> a good answer ;-)
> 

No, you can't do it w/in Velocity.  But you can create a...


...wait for it...


Tool!  


$perlLikeRenderer.doit("$$FOO_NAME");

Should be passing "$proper_foo" into the doit() method, and then you know
what to do :)

-- 
Geir Magnusson Jr.
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>