You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Darren Davison <da...@davison.uk.net> on 2004/05/31 11:22:27 UTC

context object names

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Slightly odd request perhaps, but is there any way in a template to be able 
to evaluate the *name* of a context object?

Given a reference $foo in the context that represents an arbitrary object, I 
need to be able to refer to the string "foo".

Or, conversely, if I have a reference $bar that equates to the String "foo" 
such that:

Hello $bar

would output:

Hello foo

..can I then get a reference to $foo somewhow (like ${$bar} )?

Regards,
- -- 
Darren Davison
Public Key: http://www.davison.uk.net/pages/key.htm
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAuvlXKLMLAN01aw0RAhwfAJ9R927QDGK2MveqbM2q7lzsnctqcgCfRL9t
g/jQafbPQN7SdAJyoXEP/KY=
=npZ7
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: context object names

Posted by Nathan Bubna <na...@esha.com>.
Darren Davison said:
> Slightly odd request perhaps, but is there any way in a template to be able
> to evaluate the *name* of a context object?

not too odd.  similar questions have been asked and answered many times
before. :)

> Given a reference $foo in the context that represents an arbitrary object, I
> need to be able to refer to the string "foo".
>
> Or, conversely, if I have a reference $bar that equates to the String "foo"
> such that:
...
> can I then get a reference to $foo somewhow (like ${$bar} )?
...

i see two options for you.  one is to use either the RenderTool or
ViewRenderTool in the VelocityTools project, and the other is to add the
current context to itself (e.g. context.put("context", context);) and do
something like:

$context.get("$bar")

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org