Question

In Magnolia 4.5.3, I'm trying to inherit a parent page's stage if none is defined for this. The Java class TemplatingFunctions (exposed as cmsfn in freemarker) provides a method inherit(Node content), so I'm trying the following:

[#if component??]
    [@cms.component content=component /]
[#else]
    [#assign inheritedContent = cmsfn.inherit(cmsfn.content(state.mainContent.@handle)) /]
    [@cms.component content=inheritedContent /]
[/#if]

But then I get an error:

The 'content' parameter must be a ContentMapModel and is a StringModel.

(line 6 in my example)

Why does this error occur, i.e. how could I resolve such an error?

Était-ce utile?

La solution 2

I wrote my own inherit method, searching manually for a parent node with a stage, but at the end, instead of returning a Node, I return new ContentMap(node).

Autres conseils

I guess the problem is that cmsfn.content(path) returns a javax.jcr.Node, and thus the overloaded cmsfn.inherit method will also return a Node, but @cms.component expects a info.magnolia.jcr.util.ContentMap. So, maybe you should convert the Node to a ContentMap with cmsfn.asContentMap(someNode). (I'm telling this without knowing anything about Magnolia, just be looking at its API javadoc, so maybe I'm wrong.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top