[MAGNOLIA-3829] Expose EL functions as shared variables. Created: 09/Sep/11  Updated: 04/Nov/15  Resolved: 04/Nov/15

Status: Closed
Project: Magnolia
Component/s: freemarker
Affects Version/s: 4.4.4
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Danilo Ghirardelli Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Java Source File StaticMethodsModel.java    
Issue Links:
relation
is related to MGNLSTK-609 Move "stk" (STKUtil) into FreeMarker ... Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

In freemarker you can use jsp tag libraries, but you can't use directly EL Functions. There is the possibility to put in the model all static methods, accessing them with statics[full.package].method(), but this has two drawbacks: you have to expose all of the static methods in your entire system, and you have to put always the complete package and classname for each call.

The attached class is a wrapper for a class, exposing all of its static methods in a map. To use this class, declare a node under /server/rendering/freemarker/sharedVariable with the name you want to use as placeholder, and two node data: "class" with the full package of this class, and "targetClass", with the full package of the class with static methods you want to expose.
For example:

 sharedVariables
  \- cmsfn
     |- class         info.magnolia.freemarker.StaticMethodsModel
     \- targetClass   info.magnolia.cms.taglibs.CmsFunctions

and then you can use ${cmsfn.canEdit()} in your template.

There were no examples on how to declare shared variables and what interfaces should be extended, I thought this may be left as an example just in case.



 Comments   
Comment by Danilo Ghirardelli [ 09/Sep/11 ]

STKUtil seems a good candidate to be exposed with this.

Comment by Michael Mühlebach [ 04/Nov/15 ]

Given the thousands of other issues we have open that are more highly requested, we won't be able to address this issue in the foreseeable future. Instead we will focus on issues with a higher impact, and more votes.
Thanks for taking the time to raise this issue. As you are no doubt aware this issue has been on our backlog for some time now with very little movement.
I'm going to close this to set expectations so the issue doesn't stay open for years with few updates. If the issue is still relevant please feel free to reopen it or create a new issue.

Generated at Mon Feb 12 03:50:05 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.