## Evaluates other macros.
#macro(eval $_macro)$_macro#end
## Calls itself recursively 10 times.
#macro(recursive $_level)
#if ($_level < 10)
<p>We are at level $_level.</p>
#set ($_level = $_level + 1)
#eval("#recursive($_level)")
#end
#end
#recursive(0)
Produces:
We are at level 0.
We are at level 1.
We are at level 2.
We are at level 3.
We are at level 4.
We are at level 5.
We are at level 6.
We are at level 7.
We are at level 8.
We are at level 9.
More complicated parameters to recursive macros must be global as they would be converted to strings when passed through #eval():
## Appends items to a global array.
#macro(append)
#set ($_size = $_array.size())
#if (($_size < 10) && $_array.add("New Item $_size"))
#eval("#append()")
#end
#end
#set ($_array = [ "First item 0" ])
#append()
<p>Array size: $_array.size()</p>
Produces:
Array size: 10
-- Ilkka
[EMAIL PROTECTED] wrote:
I am using the latest available release (1.3rc2) and am being bitten badly by the bug described here:
http://issues.apache.org/bugzilla/show_bug.cgi?id=13623
"Use of Velocimacro forward reference and/or recursion causes error messages"
error : too few arguments to macro.
Use of recursion is critical to me, as I use Velocity to render a tree structure recursively, which would be very cumbersome to do with JSP or straight servlets.
Is there a safe version of Velocity which implements recursion?
Aaron Hamid
Cornell University
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
.
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
