You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Victor Salaman <vs...@hotmail.com> on 2001/12/22 15:15:29 UTC

Dynamic context resolution in template

Hi:

I was wondering if there is some way of achieving dynamic context parameter 
resolution.

For example, let's say I have

$name='John Smith'
$city='West Palm Beach'
$state='Florida'

and I have $selector

if $selector is 'name' would there be some kind of syntax (or something in 
the api that I can use) so it resolves dynamically to 'John Smith'?

/V

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


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


Re: Dynamic context resolution in template

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/22/01 9:15 AM, "Victor Salaman" <vs...@hotmail.com> wrote:

> Hi:
> 
> I was wondering if there is some way of achieving dynamic context parameter
> resolution.
> 
> For example, let's say I have
> 
> $name='John Smith'
> $city='West Palm Beach'
> $state='Florida'
> 
> and I have $selector
> 
> if $selector is 'name' would there be some kind of syntax (or something in
> the api that I can use) so it resolves dynamically to 'John Smith'?
> 

No - this is another spin on the problem if iterative evaluation, I think.
You want to do something like
  

  ${$selector}

Right?  To get  $name - > 'John Smith'

We don't do that.

However, there are a few outs for you.  For example, put the context itself
into the context :

  context.put("context", context )

And then

  $context.get( $selector )

Should do the trick for you.

You can get fancier with your own eval tool, but I think the above might
work for you if I understand the problem correctly.

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin



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