velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Revusky <...@revusky.com>
Subject Re: Macros with large input on parameters
Date Fri, 16 May 2003 19:54:55 GMT
Nathan Bubna wrote:
> Jeremy said:
> 
>>I am curious if it is possible to have macros with large input. I'll
> 
> give a
> 
>>simple example:
>>
>>#macro (block $title $body)
>><table class="Block">
>><tr><td class="BlockTitle">$title</td></tr>
>><tr><td class="BlockContents">$body</td></tr>
>></table>
>>#end
> 
> ...
> 
>>In the $body parameter, I would like to be able to run #foreach ...
> 
> #end's,
> 
>>have tables inside of it, etc...
> 
> ...
> 
>>Is their a way to accomplish this?
> 
> 
> and a really quick search of the archives reveals...
> 
> http://marc.theaimsgroup.com/?l=velocity-user&w=2&r=1&s=block+macro&q=
> b


Yeah, I think such a search reveals that Velocity doesn't have the 
feature the person is requesting. You cannot associate a nested block 
with a velocity macro. I think that's the feature the poster wants. 
Like, in FreeMarker, you could define the macro "thrice" like so:

<#macro thrice>
    <#nested>
    <#nested>
    <#nested>
</#macro>

and then you could invoke it:

<@thrice>
    blah blah
</@thrice>

and that would output:

    blah blah
    blah blah
    blah blah

But the blah blah within the invocation could contain any arbitrary 
template text, including variable insertions, loops, and invocations of 
other macros and so on. And, of course the nested block could be a 
thousand lines long, if necessary. No problem.

I notice that this idea has been floated separately on the Vel list and 
people thought it was interesting. But, as far as I know, it was never 
implemented -- mostly, I think, because of the lack of an active 
developer community.

The only solution that comes to mind is to use a template engine that 
has the feature -- like,... ahem, FreeMarker. Here's the manual section 
that explains how this works:

http://freemarker.org/docs/dgui_misc_userdefdir.html


It could be of interest if someone wants to implement this idea.

Best Regards and Greetings from the Dark Side,

Jonathan Revusky
--
lead developer, FreeMarker project, http://freemarker.org/




> 
> 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