velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: Can I write a macro that can call itself?
Date Fri, 13 Jul 2001 01:08:28 GMT
Uday Kumar wrote:
> 
> Hi
> 
> I am very new to velocity. i have a question... I wanna do recursion using
> velocity. There is an example in the documentation where the .vm file calls
> itself. But, what i am wondering is - Can a macro call itself? Is that
> permitted in velocity? "Can I write a macro that can call itself?" is my
> ultimate question....

Yep.  Recursion works fine.

See the xml example - that is a recursive Velocimacro that walks a JDOM
tree.

Note that this can be a messy subject - since the default behavior of
any #set() is to modify the 'global' context, you can step on yourself
if you are not careful.

There is a switch though, that makes every #set() in a VM local to that
VM (like a local / automatic variable...)

velocimacro.context.localscope = true

Rather than a long winded explination from me, just play with it, and
come back with any questions...

geir



> 
> Please let me know
> 
> Thanks in advance
> 
> -Uday

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Mime
View raw message