aemslingsightlyhtl

Sightly Implicit Objects


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!


Solution

  • 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