【问题标题】:Sightly Implicit Objects视觉隐含对象
【发布时间】:2019-05-15 06:57:54
【问题描述】:

我正在尝试实现我自己版本的 WCM 导航组件,其 logic can be found here 替换为我自己的逻辑:

import java.util.*;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageFilter;

import com.adobe.cq.sightly.WCMUsePojo;

public class Navigation extends WCMUsePojo{
    private Iterator<Page> items;

    @Override
    public void activate() throws Exception {
        Page navRootPage = getCurrentPage().getAbsoluteParent(2);
        items = navRootPage.listChildren(new PageFilter());
    }
    public Iterator<Page> getItems() {
        return items;
    }
}

HTL found here 是相同的。

我能够遍历导航项的第一级(深度 4)。但是循环在item.html 在这一行中断: &lt;sly data-sly-test="${item.children.size &gt; 0}" data-sly-call="${groupTemplate.group @ items = item.children}"&gt;&lt;/sly&gt;

具体来说,item.children 似乎不起作用,即使这些是隐式 Sling 对象。关于为什么会出现这种情况的任何想法?

提前致谢!

【问题讨论】:

    标签: aem sling sightly htl


    【解决方案1】:

    核心 WCM 组件中实现的 Navigation 模型返回一个 NavigationItem 列表,这些列表通过 getChildren 方法公开其子级。这使您可以使用 item.children 从 HTL/Sightly 调用它。由于您的 use-object 返回 WCM Pages 的列表,因此您需要使用 listChildren 方法。您可以使用 item.listChildren 直接从 HTL/Sightly 调用它。

    通常,对于所有对象,您都可以使用标准 JavaBeans 约定调用属性获取器,请参阅https://helpx.adobe.com/experience-manager/htl/using/use-api-java.html#Gettermethods。有关 HTL/Sightly 中 AEM 上下文中可用的所有对象的列表,请参阅:https://helpx.adobe.com/experience-manager/htl/using/global-objects.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      相关资源
      最近更新 更多