【问题标题】:cmsfn.inherit() seems to return wrong typecmsfn.inherit() 似乎返回错误的类型
【发布时间】:2023-03-14 12:15:01
【问题描述】:

在 Magnolia 4.5.3 中,如果没有为此定义父页面,我将尝试继承父页面的阶段。 Java 类TemplatingFunctions(在freemarker 中暴露为cmsfn)提供了一个方法inherit(Node content),所以我正在尝试以下方法:

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

然后我得到一个错误:

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

(在我的示例中为第 6 行)

为什么会出现这个错误,即我该如何解决这个错误?

【问题讨论】:

    标签: freemarker magnolia


    【解决方案1】:

    我猜问题是cmsfn.content(path) 返回一个javax.jcr.Node,因此重载的cmsfn.inherit 方法也会返回一个Node,但@cms.component 需要一个info.magnolia.jcr.util.ContentMap。所以,也许你应该将Node 转换为ContentMapcmsfn.asContentMap(someNode)。 (我是在不了解 Magnolia 的情况下这么说的,只是看看它的 API javadoc,所以也许我错了。)

    【讨论】:

    • 是的,类型是问题之一,但我必须使用 new ContentMap(node) 才能让它工作。
    【解决方案2】:

    我编写了自己的继承方法,手动搜索具有阶段的父节点,但最后,我没有返回节点,而是返回new ContentMap(node)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 2011-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多