Re: [Freemarker-user] macro override

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Sunday, December 20, 2009, 7:52:07 PM, Argyro Kazaki wrote:

> Halo all,
>
> I have two files, a.ftl and b.ftl and this is also the order in which 
> they are loaded.
>
> Within a.ftl I have the following macro:
>
> <#macro foo pojo>
>     <#-- do stuff with pojo -->
> </#macro>
>
> Within b.ftl I have a macro with the same signature, which naturally 
> overrides the first (because b.ftl it is loaded after a.ftl):
>
> <#macro foo pojo>
>     <#-- do stuff with pojo -->
> </#macro>
>
> Is there a way to call the first macro within the latter? I am trying to
> achieve something similar like overriding java methods and still being
> able to call super implementation.

Unfortunately no. In FreeMarker macros are just variables. So when you
import b.ftl, it just like when you set the foo variable... the old
value of foo is lost. (One would think that the old variable could be
saved before its overwritten with some name like super_foo, but the
feature that allows calling macros that are defined later will
interfere with this, and it's the new macro that will be saved.)

If you are using #import, since then the macros will have a prefix, it
is possible to call the other "foo"... but then you don't have
overriding, so this is certainly not useful for you. But if the
inheritance hierarchy is static, you could <#import "a.ftl" as super>
in "b.ftl", then you can call <@super.foo pojo /> there... of course
that's very far from real inheritance for obvious reasons.

> Is it possible to do something like this within b.ftl so that the inner
> @foo call be redirected to super implementation? (of course now ends 
> with a StackOverflowError)
>
> <#macro foo pojo>
>     <#-- do stuff with pojo -->
>     <@foo pojo />
> </#macro>
>
>
> Thanks,
> Argyro Kazaki
>
>
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev 
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.