Hi Ernst!

I use the sharedVariables to access my own objects from freemarker templates.

It is working well.

All the objects I set as shared vars are subclasses of TemplateDirectiveModel, 
since I want to use them as directives.

If you have a class you want to use that does not implement one of the model 
methods, why not create a delegate object to wrap the class you actually want 
to share?

Regards from Vienna,

Richard




-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] 
Im Auftrag von Ernst Bunders
Gesendet: Mittwoch, 15. Juni 2011 15:06
An: Magnolia User-List
Betreff: [magnolia-user] freemarker sharedVariables and static methods


hi

I have a class with a bunch of static methods that I want to access from 
freemarker templates.
According 
to http://freemarker.sourceforge.net/docs/pgui_misc_beanwrapper.html#autoid_55
I can do something like

BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
TemplateHashModel staticModels = wrapper.getStaticModels(); TemplateHashModel 
fileStatics =
    (TemplateHashModel) staticModels.get("java.io.File");

for my class and that's it.

But the shardVariables map simply maps names to classes that can be 
instantiated as TemplateModel.

It seems that what i actually need is a kind of factory or factory method that 
will create the TemplateModel instance, in stead of straight instantiation.

Is there something I miss, or is it simply not possible with the current setup?

I also found  http://jira.magnolia-cms.com/browse/MAGNOLIA-3152
I think this issue addresses the same problem. Can I assume that the fact this 
issue is still open means that some work is still needed to make this possible?

If so, I can extend FreemarkerHelper, but I rather don't if not needed.

regards,


--
Ernst Bunders
Ontwikkelaar VPRO


----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------





----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to