velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nbu...@gmail.com>
Subject Re: Parameterised "Tiles-type" inserts, locally scoped context, etc?
Date Mon, 22 Aug 2005 15:25:50 GMT
This is essentially what velocimacros are designed to solve.  I would
recommend using them.  And it really doesn't cost you anything to
"include" (not sure about the use of that word) them all in case
they're used.  Just put them in a velocimacro library that is loaded
once on startup.  Then they'll automatically be available to all your
templates at less cost than specifying them locally in the templates.

On 8/22/05, Maurice Nicholson <maurice.nicholson@opodo.com> wrote:
> Hi all,
> 
> maybe this is a stupid question, but is it possible to include another
> template with named parameters?
> 
> Eg, I have an "address" object which I need to display several times, but
> there are several different locations of my address object within the object
> model. I don't want to copy and paste the bit of address-display template
> each time.
> 
> Therefore I want a way to do:
> 
> ## include the "addressDisplay.vm" template (with $address =
> $delivery.address)
> 
> and somewhere else it might be
> 
> ## include the "addressDisplay.vm" template (with $address =
> $creditCard.billingAddress)
> 
> Then in my addressDisplay.vm, use "$address" as a regular context variable.
> 
> Furthermore, it would be nice if the context in the included template was
> locally scoped to the included template only, and did not affect the
> "parent" template's context.
> 
> I know I can do:
> 
> #set( $address = $delivery.address )
> #parse( "addressDisplay.vm" )
> 
> ...
> 
> #set( $address = $creditCard.billingAddress )
> #parse( "addressDisplay.vm" )
> 
> but (1) I have to remember to set $address before each #parse and (2) I
> might already have an $address in the current template that I don't want to
> interfere with. If I had several "parameters" to pass to the included
> template, it quickly gets verbose and error prone. Is this the best way?
> 
> I've seen the TilesTool documentation, but it doesn't seem to offer this
> kind of functionality.
> 
> Maybe I could define "addressDisplay" as an included macro and pass the
> address object to it. But then if I have lots of reusable bits of template,
> I would have to include them all in case they're used.
> 
> Any recommendations?
> 
> Many thanks,
> Maurice
> 
> 
> 
> ________________________________________________________________________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ________________________________________________________________________
>

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


Mime
View raw message