[ https://issues.apache.org/jira/browse/VELOCITY-666?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12663600#action_12663600 ]
Byron Foster commented on VELOCITY-666: --------------------------------------- I've thought about the syntax of being able to call a macro like so: #macro(bold $txt)<b>$txt</b>#end $bold("text") This generalizes macro definitions and allows setting: #set($bold2 = $bold) $bold2("text") I'm not real big on #define, it seems like a partial solution to me, mainly because it does not allow parameters, and now you have essentially two types of macros without much gain for the complexity. For blocks I think you could simply do: #bold("text") #begin <strong>$txt</strong> #end or, $bold("text") #begin <strong>$txt</strong> #end The macro call would be smart about the #begin block following the macro call and pass it as a parameter. Figures the 666 issues would create a discussion :) > RFC: new directive: #call > ------------------------- > > Key: VELOCITY-666 > URL: https://issues.apache.org/jira/browse/VELOCITY-666 > Project: Velocity > Issue Type: Improvement > Affects Versions: 1.6.2, 1.7 > Reporter: Jarkko Viinamäki > Attachments: velocity-call-directive.patch > > > Inspired by VELOCITY-583 (BlockMacro support) I implemented the same > functionality in a slightly different way. > This patch introduces a new directive #call("mymacro" $arg1 $arg2 ... ) any > valid Velocity content here #end > This directive causes a call to defined macro with given arguments AND passes > the enclosed AST as an argument which can be referenced with $bodyContent > (default, name is configurable). > An example: > #set($foobar = "yeah!") > > #macro(strong $txt) > <strong>$bodyContent</strong> $txt > #end > #call("strong" $foobar) > <u>This text is underlined and bold</u> > #end > > Will print: > <strong><u>This text is underlined and bold<u></strong> yeah! > Like I commented in VELOCITY-583 the same thing can be done by first using > #define to build up some custom AST and then pass that AST as an argument to > some macro. While it works, it's not as convenient as this syntax. This patch > however increases the amount of code lines in Velocity and the implementation > is a bit "hackish" so even I'm not totally convinced whether we should commit > this. > But anyway, here it is, I'd love to hear your comments. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org For additional commands, e-mail: dev-h...@velocity.apache.org