|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
taglib functions in freemarkerhi templaters! i understand that i can use any j2ee taglib tag in freemarker, also i can use those cool freemarker functions. does anybody know, if it is possible to use taglib *functions* within freemarker templates/paragraphs, resp how-to accomplish that? background: we plan to use stk and stk best practices eg freemarker templating, also fell in love with openutils simple media module which usage is very much based on taglib functions, as of http://lab.openmindonline.it/lab/products/media/docs/integrate.html - see "taglibdocs". taglib functions within freemarker? anybody let me know... regards jf ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <user-list-unsubscribe@...> ---------------------------------------------------------------- |
|
|
Re: taglib functions in freemarkerJochen Fliedner wrote: > i understand that i can use any j2ee taglib tag in freemarker, also i > can use those cool freemarker functions. > > does anybody know, if it is possible to use taglib *functions* within > freemarker templates/paragraphs, resp how-to accomplish that? > > background: we plan to use stk and stk best practices eg freemarker > templating, also fell in love with openutils simple media module > which usage is very much based on taglib functions, as of > http://lab.openmindonline.it/lab/products/media/docs/integrate.html - > see "taglibdocs". > > > taglib functions within freemarker? anybody let me know... Does the 'JSP Tags' section at http://documentation.magnolia-cms.com/reference/freemarker.html answer your question? Nils Breunese. ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <user-list-unsubscribe@...> ---------------------------------------------------------------- |
|
|
Re: taglib functions in freemarker2009/11/12 Nils Breunese <n.breunese@...>: > > Jochen Fliedner wrote: > >> i understand that i can use any j2ee taglib tag in freemarker, also i >> can use those cool freemarker functions. >> >> does anybody know, if it is possible to use taglib *functions* within >> freemarker templates/paragraphs, resp how-to accomplish that? >> >> background: we plan to use stk and stk best practices eg freemarker >> templating, also fell in love with openutils simple media module >> which usage is very much based on taglib functions, as of >> http://lab.openmindonline.it/lab/products/media/docs/integrate.html - >> see "taglibdocs". >> >> >> taglib functions within freemarker? anybody let me know... > > Does the 'JSP Tags' section at > http://documentation.magnolia-cms.com/reference/freemarker.html answer your > question? > Nope, it does not. This is indeed something I stumbled upon myself, asked before on this list, and am currently inclined to believe unsupported. There is no information (i could find) on the web about freemaker and EL functions. But there is one thing I still need to try: As EL functions tend to be static methods, it should be possible to call them directly. I don't know enough about freemarker yet to be sure you can just do something like ${path.to.Class.staticMethod(param1, paran2)}, but I expect you can. If it turns out that you can't you can perhaps extend the FreemarkerTemplateRenderer or STKTemplateRenderer class and add a reference to this class to the template rendering context. regards, Ernst > Nils Breunese. > > ---------------------------------------------------------------- > For list details see > http://www.magnolia-cms.com/home/community/mailing-lists.html > To unsubscribe, E-mail to: <user-list-unsubscribe@...> > ---------------------------------------------------------------- > > -- Ernst bunders Ontwikkelaar VPRO ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <user-list-unsubscribe@...> ---------------------------------------------------------------- |
|
|
Re: taglib functions in freemarker2009/11/12 Ernst Bunders <ebunders@...>: > 2009/11/12 Nils Breunese <n.breunese@...>: >> >> Jochen Fliedner wrote: >> >>> i understand that i can use any j2ee taglib tag in freemarker, also i >>> can use those cool freemarker functions. >>> >>> does anybody know, if it is possible to use taglib *functions* within >>> freemarker templates/paragraphs, resp how-to accomplish that? >>> >>> background: we plan to use stk and stk best practices eg freemarker >>> templating, also fell in love with openutils simple media module >>> which usage is very much based on taglib functions, as of >>> http://lab.openmindonline.it/lab/products/media/docs/integrate.html - >>> see "taglibdocs". >>> >>> >>> taglib functions within freemarker? anybody let me know... >> >> Does the 'JSP Tags' section at >> http://documentation.magnolia-cms.com/reference/freemarker.html answer your >> question? >> > > Nope, it does not. This is indeed something I stumbled upon myself, > asked before on this list, and am currently inclined to believe > unsupported. > There is no information (i could find) on the web about freemaker and > EL functions. > > But there is one thing I still need to try: As EL functions tend to be > static methods, it should be possible to call them directly. I don't > know enough about freemarker yet to be sure you can just do something > like ${path.to.Class.staticMethod(param1, paran2)}, but I expect you > can. > > If it turns out that you can't you can perhaps extend the > FreemarkerTemplateRenderer or STKTemplateRenderer class and add a > reference to this class to the template rendering context. I found out that indeed the TemplateRenderer class has to be extended. It turns out you have to wrap any java objects you want in your freemaker objects in so called 'bean wrappers'. here is a snippet of code that shows how to wrap some class in such a way that all static methods become available: BeansWrapper wrapper = BeansWrapper.getDefaultInstance(); TemplateHashModel staticModels = wrapper.getStaticModels(); TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get("java.io.File"); assuming 'root' is your context object, you can: root.put("File", fileStatics); and then in the template do this: <#list File.listRoots() as fileSystemRoot>...</#list> So this can also be done with static EL function methods. regards, Ernst > > regards, > > Ernst > >> Nils Breunese. >> >> ---------------------------------------------------------------- >> For list details see >> http://www.magnolia-cms.com/home/community/mailing-lists.html >> To unsubscribe, E-mail to: <user-list-unsubscribe@...> >> ---------------------------------------------------------------- >> >> > > > > -- > Ernst bunders > Ontwikkelaar VPRO > -- Ernst bunders Ontwikkelaar VPRO ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <user-list-unsubscribe@...> ---------------------------------------------------------------- |
|
|
Re: taglib functions in freemarkerErnst Bunders wrote: > 2009/11/12 Nils Breunese <n.breunese@...>: >> Jochen Fliedner wrote: >>> taglib functions within freemarker? anybody let me know... >> Does the 'JSP Tags' section at >> http://documentation.magnolia-cms.com/reference/freemarker.html answer your >> question? > > Nope, it does not. This is indeed something I stumbled upon myself, > asked before on this list, and am currently inclined to believe > unsupported. > There is no information (i could find) on the web about freemaker and > EL functions. That page says: "FreeMarker optionally supports JSP tag libraries, and we have enabled this feature in Magnolia too. You can use any tag library in your FreeMarker, and that means you can use the Magnolia tags too." I haven't tried it yet, but are you saying that it is not true that you can use any tag library? Nils Breunese. ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <user-list-unsubscribe@...> ---------------------------------------------------------------- |
|
|
Re: taglib functions in freemarker> That page says: "FreeMarker optionally supports JSP tag libraries, and we > have enabled this feature in Magnolia too. You can use any tag library in > your FreeMarker, and that means you can use the Magnolia tags too." That's right. But i think there is a clear distinction between EL functions, which actually is a feature of the (jsp) Expression Language, and jsp Tags. The two are bound together only in the tld, I suppose. Support for tag libraries and thus tags is well documented (and used by magnolia), but the same does not seem to apply to EL functions. But I'm not sure. I just couldn't find any documentation on this subject, and my attempts to use EL functions from a taglib. did not succeed :-( regards, Ernst ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <user-list-unsubscribe@...> ---------------------------------------------------------------- |
|
|
RE: taglib functions in freemarkerHi Ernst, >> If it turns out that you can't you can perhaps extend the >> FreemarkerTemplateRenderer or STKTemplateRenderer class and add a >> reference to this class to the template rendering context. > >I found out that indeed the TemplateRenderer class has to be extended. >It turns out you have to wrap any java objects you want in your >freemaker objects in so called 'bean wrappers'. here is a snippet of >code that shows how to wrap some class in such a way that all static >methods become available: > >BeansWrapper wrapper = BeansWrapper.getDefaultInstance(); >TemplateHashModel staticModels = wrapper.getStaticModels(); >TemplateHashModel fileStatics = > (TemplateHashModel) staticModels.get("java.io.File"); > >assuming 'root' is your context object, you can: >root.put("File", fileStatics); > >and then in the template do this: ><#list File.listRoots() as fileSystemRoot>...</#list> > >So this can also be done with static EL function methods. Thats cool! I think a FreemarkerHelper subclass is the correct place to do such thing. One can subclass FreemarkerTemplateRenderer (Justas STKParagraphRenderer does) and construct it with an own helper class - so you have an own renderer for your project. Also you can implement model classes and use MediaEl within it. It makes sense as a kind of MVC pattern anyway. I checked the freemarker code and it became obvious to me that indeed there is no generic taglib functions support. (Correct me if I am wrong!) Anyway it might collide with the freemarker EL syntax, as i did like [#assign media=JspTaglibs["http://net.sourceforge.openutils/mgnlMedia"]] <img src="${contextPath}/${media}" alt="XXX" /> it resulted in freemarker.core.NonStringException: Error on line 12, column 36 in templating-kit/paragraphs/teasers/internalPage. Expecting a string, date or number here, Expression media is instead a freemarker.ext.jsp.TaglibFactory$Taglib Of course ${media:something}, ${media.something}... no way. However I can go on with the mentioned solution in our project. Thanks a lot, regards j ---------------------------------------------------------------- For list details see http://www.magnolia-cms.com/home/community/mailing-lists.html To unsubscribe, E-mail to: <user-list-unsubscribe@...> ---------------------------------------------------------------- |
| Free embeddable forum powered by Nabble | Forum Help |