logo       

Re: html macro library: msg#00197

jakarta.velocity.user

Subject: Re: html macro library

Nathan Bubna wrote:
Kevin said:
...

My experiments to start such a library seem doomed as I would really
need to be able to applied recursively so as to embed one tag in
another.


your experiments are doomed if you believe everything you're told without ever
questioning it. there are ways:

#macro( feedmetome $foo )this is $foo#end
#macro( recursor )
#if( $i < 10 )
#set( $i = $i + 1 )
recursing #recursor()
#end
#end

#set( $bar = "#feedmetome( 'bar' )" )
#feedmetome( "#feedmetome( $bar )" )
#set( $i = 1 )
#recursor()

Nathan,

I did not mean to imply that the above example does not work.

What I meant was that if you write a macro library that largely wraps HTML functionality, you will want to be able to pass a block of template code to such a macro. IOW, in the general case, you will want for $text in:

#html_href($link, $text)

to be an arbitrary block, possibly containing invocations of other macros (for formatting purpose etc.) and so on.

I watch this list off-and-on and I seem to recall this kind of thing coming up. I think that recently somebody even implemented a special #defineblock macro so that a block could be passed around as a parameter in such cases.


but use Freemarker if it better suits your needs.

The ability to pass in a block (co-routine for language design buffs) as a parameter to an FTL macro was introduced in FreeMarker 2.2. See:

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

This does make certain things possible that would be extremely tortuous to implement with Velocimacros -- or even outright impossible.

Regards,

Jonathan Revusky
--
lead developer, FreeMarker project, http://freemarker.org/
FreeMarker-Velocity comparison page: http://freemarker.org/fmVsVel.html

FreeMarker 2.3 pre1 is out!


Nathan Bubna
nathan@xxxxxxxx


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise