明显的隐式对象 [英] Sightly Implicit Objects

查看:95
本文介绍了明显的隐式对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现我自己的WCM导航组件版本,其导航组件可以在这里找到逻辑,代替我自己的逻辑:

I am trying to implement my own version of WCM's navigation component, whose logic can be found here, subbing my own logic instead:

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,在这里找到,完全相同。

The HTL, found here, is identical.

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

I am able to iterate over the first level (at depth 4) of the navigation items. But the loop breaks in item.html at this line: <sly data-sly-test="${item.children.size > 0}" data-sly-call="${groupTemplate.group @ items = item.children}"></sly>

具体地说,即使 item.children 似乎是无效的,即使它们是隐式的Sling对象。对此有何想法?

Specifically, item.children does not appear to work even though these are implicit Sling objects. Any thoughts on why this is breaking?

预先感谢!

推荐答案

在核心WCM组件中实现的 Navigation 模型返回 NavigationItem ,它通过 getChildren 方法公开其子级。这样,您就可以使用 item.children 从HTL / Sightly中调用它。由于您的使用对象返回了WCM的列表,因此 页面 s,则需要使用 listChildren 方法。您可以使用 item.listChildren 从HTL / Sightly直接调用它。

The Navigation model implemented in the Core WCM Components returns a list of NavigationItem which expose their children via a getChildren method. That allows you to call it from HTL/Sightly with item.children. Since your use-object returns a list of WCM Pages, you need to use the listChildren method. You can call it directly from HTL/Sightly using item.listChildren.

通常,对于所有对象,可以使用标准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

In general, for all objects, you can invoke a property getter using the standard JavaBeans conventions, see https://helpx.adobe.com/experience-manager/htl/using/use-api-java.html#Gettermethods. For a list of all objects available in AEM context in HTL/Sightly, see: https://helpx.adobe.com/experience-manager/htl/using/global-objects.html

这篇关于明显的隐式对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆