Sightly Implicit Objects

故事扮演 提交于 2019-12-25 02:45:12

问题


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;
    }
}

The HTL, found here, is identical.

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>

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

Thanks in advance!


回答1:


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.

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



来源:https://stackoverflow.com/questions/53772366/sightly-implicit-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!