Re: Multiple types

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
The type-system of FTL (for FreeMarker Template Language) corresponds
to the TemplateMoldel interfaces. Since a class can implement several
interfaces at once, you have multi-typing. Like, TemplateNumberModel
plus TemplateHashModel, an instance of that class will be both a
number and a hash for FTL. So creating multi-typed values is trivial
as you see, however it's something that you do outside the templates
(there is no FTL operator or literal to create a multi-typed values).

Unfortunately, I'm afraid you are out of luck with macros, however.
I'm not the author of the FM code-base so possibly I miss something...
but most probably I don't. So the problem is that as far as the public
API is concerned, macros is a mess in FM. (Maybe because they are
ancient pre-TemplateModel constructs... I don't know). A macro is an
instance of freemarker.core.Macro, which is a final class, not an
interface. Plus, calling a macro in Java through a Macro object
requires you to access the freemarker.core.Environment.visit(Macro,
...etc) method, which is not a public method. Thus, as far as I see,
you just can't mix TempalateHashModel in for purely technical reasons.
So unless using TemplateDirectiveModel-s or TemplateMethodModel-s
instead of macros works for you, you are out of luck.


Sunday, June 27, 2010, 12:49:50 PM, Alex Robinson wrote:

> I note this in the documentation:
>
> "A value can have multiple types at the same time, although it's
> rarely utilized"
> 
> http://freemarker.sourceforge.net/docs/dgui_datamodel_basics.html#autoid_13
>
> However I don't understand how it's actually possible to use.
>
> I'm interested in this feature (at first read I dismissed it as scary)
> since it would allow me to group macros like
>
>    macro1, macro1.submacro1
>
> rather than
>
>    macro1, macro1Submacro1
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> 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 Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
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.