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

freemarker MagnoliaObjectWrapper should wrap any Content instance info.magnolia.freemarker.models.ContentModel, also if the given Content also implements Map

XMLWordPrintable

      If you try to use a Content object which also implements Map in a freemarker template (e.g. if the object is not DefaultContent but info.magnolia.cms.util.NodeMapWrapper) it gets not wrapped properly using info.magnolia.freemarker.models.ContentModel as expected.

      This is due to the fact that the custom wrapper only gets used if standard freemarker adapters are not available, so implementing Map is enough to make freemarker skip the Magnolia factories...
      This is the same issue we had in the past with the "Context" object, and we already have a specific check in the wrap() method of MagnoliaObjectWrapper:

          public TemplateModel wrap(Object obj) throws TemplateModelException {
              if (obj instanceof Context) {
                  // bypass the default SimpleHash wrapping, we need a MapModel.
                  // handleUnknownType() will relay to our ContextModelFactory.
                  return handleUnknownType(obj);
              }
              return super.wrap(obj);
          }
      

      the proposed change is to also add "Content" to the list of objects that should always we wrapped using Magnolia-specific adapters:

          public TemplateModel wrap(Object obj) throws TemplateModelException {
              if (obj instanceof Context || obj instanceof Content) {
                  // bypass the default SimpleHash wrapping, we need a MapModel.
                  // handleUnknownType() will relay to our ContextModelFactory.
                  return handleUnknownType(obj);
              }
              return super.wrap(obj);
          }
      

        Acceptance criteria

              fgiust Fabrizio Giustina
              fgiust Fabrizio Giustina
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Task DoD