视觉隐式对象
Sightly Implicit Objects
我正在尝试实现我自己的 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
这一行中断:
<sly data-sly-test="${item.children.size > 0}" data-sly-call="${groupTemplate.group @ items = item.children}"></sly>
具体来说,item.children
似乎不起作用,即使这些是隐式 Sling 对象。想知道为什么会这样吗?
提前致谢!
的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 Page
s,需要用到listChildren
的方法。您可以使用 item.listChildren
.
直接从 HTL/Sightly 调用它
通常,对于所有对象,您可以使用标准 JavaBeans 约定调用 属性 getter,请参阅 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
我正在尝试实现我自己的 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
这一行中断:
<sly data-sly-test="${item.children.size > 0}" data-sly-call="${groupTemplate.group @ items = item.children}"></sly>
具体来说,item.children
似乎不起作用,即使这些是隐式 Sling 对象。想知道为什么会这样吗?
提前致谢!
的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 Page
s,需要用到listChildren
的方法。您可以使用 item.listChildren
.
通常,对于所有对象,您可以使用标准 JavaBeans 约定调用 属性 getter,请参阅 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