Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-3829

Expose EL functions as shared variables.

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Neutral Neutral
    • None
    • 4.4.4
    • freemarker
    • None
    • Yes

      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.

        Acceptance criteria

              Unassigned Unassigned
              dfghi Danilo Ghirardelli
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Task DoD