velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John McNair" <jmcn...@enox.com>
Subject RE: is it possible to maintain a foreach directive after a VelocityEngine.evaluate()?
Date Mon, 30 Apr 2012 19:09:08 GMT
I'm not above faking it :)

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: Monday, April 30, 2012 3:06 PM
To: Velocity Users List; jmcnair@enox.com
Subject: Re: is it possible to maintain a foreach directive after a
VelocityEngine.evaluate()?

No, i don't think there's a way to do that automatically without customizing
your velocity build.  But you can fake it:

#set( $h = '#')
#set( $d = '$' )
#foreach( $element in $object1.elements )

#end
#if( !$object1 )
${h}foreach( ${d}element in $object1.elements )

${h}end
#end

On Mon, Apr 30, 2012 at 11:44 AM, John McNair <jmcnair@enox.com> wrote:
> Hi,
>
>
>
> I have an oddball case where I need a multi-stage Velocity template 
> evaluation.  That is, image a pipelined process where:
>
>
>
> -          Task one grabs a Velocity template, adds some (but not all) 
> items to the Context, evaluates, and sends the partially resolved 
> output as input to task two
>
> -          Task two adds some (but not all) items to the Context,
evaluates.
>
>
>
> I know I can have variables like ${object1.member1} that will be 
> preserved in the output after evaluate() if object1 is not resolved, 
> however, is it possible to maintain a foreach directive after an
evaluation:
>
>
>
> ## preserve this 'foreach' in the output if object1 is not resolved
>
> #foreach( $element in $object1.elements )
>
> #end
>
>
>
> Thanks in advance,
>
> John
>


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


Mime
View raw message