velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maurice Nicholson <maurice.nichol...@opodo.com>
Subject Parameterised "Tiles-type" inserts, locally scoped context, etc?
Date Mon, 22 Aug 2005 11:25:16 GMT
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
________________________________________________________________________
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message