You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Ford, Peter" <Pe...@travelocity.com> on 2004/05/13 18:37:36 UTC
Nesting Velocity tags
Question: Can Velocity recursively process tags found inside values returned from the context?
Here's a simplified example of what I'm talking about. My template may contain something like:
===
My name is ${name}.
===
In the context I have these key/value pairs:
first=Fred
last=Bloggs
name=${first} ${last}
When I process the template against that context, I would like to see:
===
My name is Fred Bloggs.
===
...but my initial tests give me:
===
My name is ${first} ${last}.
===
Possibly I'm doing something wrong, possibly there's a very simple way to make it do what I need and I'm just not seeing it. Unfortunately this isn't a hypothetical situation - this is something I have to get working, and I'm running out of time. If anyone knows the answer I'd appreciate it.
Thanks,
Pete
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Nesting Velocity tags
Posted by Nathan Bubna <na...@esha.com>.
Ford, Peter said:
...
> Here's a simplified example of what I'm talking about.
> My template may contain something like:
>
> ===
> My name is ${name}.
> ===
>
> In the context I have these key/value pairs:
>
> first=Fred
> last=Bloggs
> name=${first} ${last}
>
> When I process the template against that context, I would like to see:
>
> ===
> My name is Fred Bloggs.
you can't do this without a tool.
this is one that should help:
http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/RenderTool.html
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
RE: Nesting Velocity tags
Posted by Tim Colson <tc...@cisco.com>.
Peter -
First off, there does not appear to be any nesting in your example, just
simple output of variables.
And since you are getting $first instead of "Fred" -- it is probably as
simple as the context does not really have that variable in it.
Try:
#set ($first = "Peter")
FIRST=$first
And show us how you are populating the context -- so we can try to help.
Cheers,
Tim
> > first=Fred
> > last=Bloggs
> > name=${first} ${last}
> >
> > When I process the template against that context, I would
> like to see:
> > ..but my initial tests give me:
> >
> > ===
> > My name is ${first} ${last}.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Nesting Velocity tags
Posted by T E Schmitz <ma...@numerixtechnology.de>.
Hi Pete,
I sympathize - I was battling against exactly this for days but I didn't
dare ask a "daft" question! (I am just amending Torque's Velocity
templates, so I am not a seasoned Velocity programmer :-( ).
Try putting the compound variable in quotation marks and make sure both
variables are actually set:
name="${first} ${last}"
Regards,
Tarlika Elisabeth Schmitz
Ford, Peter wrote:
> first=Fred
> last=Bloggs
> name=${first} ${last}
>
> When I process the template against that context, I would like to see:
>
> ===
> My name is Fred Bloggs.
> ===
>
> ..but my initial tests give me:
>
> ===
> My name is ${first} ${last}.
> ===
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
RE: Nesting Velocity tags
Posted by Tim Colson <tc...@cisco.com>.
Doh!
Apologies... That will teach me to read the reply before the original
question! Oops! :-)
To answer your question, which involves double parsing -- No. <grin>
Cheers,
Tim
> ===
> My name is ${name}.
> ===
>
> In the context I have these key/value pairs:
>
> first=Fred
> last=Bloggs
> name=${first} ${last}
>
> When I process the template against that context, I would like to see:
>
> ===
> My name is Fred Bloggs.
> ===
>
> ...but my initial tests give me:
>
> ===
> My name is ${first} ${last}.
> ===
>
> Possibly I'm doing something wrong, possibly there's a very
> simple way to make it do what I need and I'm just not seeing
> it. Unfortunately this isn't a hypothetical situation - this
> is something I have to get working, and I'm running out of
> time. If anyone knows the answer I'd appreciate it.
>
> Thanks,
> Pete
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org