[
http://jira.magnolia-cms.com/browse/MGNLSTK-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=26582#action_26582
]
Grégory Joseph commented on MGNLSTK-577:
----------------------------------------
Ernst,
I don't know the internals of FreeMarker's staticModels feature, but since
MAGNOLIA-3087, this is also possible by registering a {{sharedVariable}} in the
FreeMarker configuration. ({{/server/rendering/freemarker/sharedVariables}})
The only condition being that your utility class must be instantiatable (via
Content2Bean/ClassFactory, i.e must be concrete and have an accessible
constructor).
Validated with a test: see
{{info.magnolia.freemarker.FreemarkerHelperTest#testCanAccessStaticMethodsOfSharedVariables}}
(in magnolia-core)
Please let me know if this would work you.
To all: regarding my point (2) above - do we want this available for all
templating engines - or do we want to keep it implementation-dependent? I guess
for JSP, we could push these variables to the ServletContext (which has a
similar lifecycle than the Freemarker {{Configuration}} object at the moment),
but this would somehow pollute the namespace (as other things end up in this
context, unrelated to rendering)
> Make it configurable what classes are included in the freemarker template
> rendering context
> -------------------------------------------------------------------------------------------
>
> Key: MGNLSTK-577
> URL: http://jira.magnolia-cms.com/browse/MGNLSTK-577
> Project: Magnolia Standard Templating Kit
> Issue Type: Improvement
> Components: templates
> Affects Versions: 1.2.3
> Reporter: Ernst Bunders
> Assignee: Grégory Joseph
> Fix For: 1.3
>
>
> It would be nice to be able to register classes under the template-renderer
> en paragraph-renderer configurations, so that those classes would be added to
> the template rendering context.
> STKTemplateRenderer could get a Map property like 'classesToInclude'
> it would be nice if modules/standard-templating-kit/template-renderers/stk
> would be watched, and new classes would be added on the fly through
> content2bean. STKTemplateRenderer would have to propagate this map to
> FreemarkerHelper
> you could do something like this in FreemarkerHelper:
> {code}
> TemplateHashModel staticModels = wrapper.getStaticModels();
> try {
> for (String name : classesToInclude.keySet()) {
> TemplateHashModel model = (TemplateHashModel)
> staticModels.get(classesToInclude.get(name));
> map.put(name, model);
> }
> } catch (TemplateModelException e) {
> e.printStackTrace();
> }
> {code}
> That way all static methods of the class are available.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.magnolia-cms.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------