velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nat...@esha.com>
Subject Re: Velocimacro argument (by-name) passing
Date Thu, 15 Jul 2004 15:13:02 GMT
Christoph Reck said:
> Rene Parra wrote:
...
> > The following fails (because you can't double-quote a piece of
> > VM code that already contains a double-quote)
> >
> > #reusableStruct( "#center( "#bold('hello - 1st div')" )"   "#center(
"#bold('hello - 2nd div')" )" )
>                     ^                                     ^   ^
^
> Just leave away the quotes. Macros always return strings. The following
> is untested, but to my knowledge should work:
>
> #reusableStruct( #center( #bold('hello - 1st div') )  #center(
#bold('hello - 2nd div') ) )

actually, i'm pretty sure i have tried this before and gotten template parse
errors.  though, i don't recall which version of velocity i was using at the
time.  so i've always used the double quotes since.  and for complex things as
described, i've just used preceding #set() statements to simplify them:

#set( $bolddiv1 = "#bold( 'hello - 1st div' )" )
#set( $bolddiv2 = "#bold( 'hello - 2nd div' )" )
#reusableStruct( "#center( $bolddiv1 )" "#center( $bolddiv2 )" )

not only will this work, but i think it's a lot more readable and
maintainable.

> NOTE: be careful with using the arguments within macros. These are just
> references to the original statement passed in to the macro call, thus
> every use will re-evaluate it. In your example it's no problem. But if
> you reference a method call or similar (e.g. the Alternator in
> VelocityTools) it will be executed every time.
...

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


Mime
View raw message