在CQ中,只需调用currentPage ()就可以轻松地访问currentPage.getPath对象。但是,我正在尝试删除任何scrip -让它们将它们分离为一个模型类,并且无法弄清楚如何访问currentPage对象。我想我可以做这样的事:
public void setResource(Resource resource){
resource.getPath()
} 但这会返回如下内容:
/content/home/subPage/jcr:content/banner我只是想要回/content/home/subPage/.我试图使用资源来获得路径,但找不到任何东西来做这件事。我知道这一定是很小的东西,我只是忽略了。谢谢你的帮助!
发布于 2013-07-02 07:34:00
您正在获得jcr:content/横幅,因为您是在调用页面中的组件的资源,而不是页面本身。
要从组件中获取当前页面,可以使用PageManager:
resource.getResourceResolver().adaptTo(PageManager.class);PageManager pageManager= 页currentPage =pageManager.getContainingPage(资源);
https://stackoverflow.com/questions/17415951
复制相似问题