I want to get sibling pages of a particular page of which I only have url
I know how to get sibling pages of the current page, I used Page class to fetch the sibling pages but
I want to know if I can do it for other pages if I have the URL.
Please help me to find out if it's possible and if so how.
Solved! Go to Solution.
Views
Replies
Total Likes
Sample code from default project structure.
@Model(adaptables = Resource.class) public class HelloWorldModel { @SlingObject private ResourceResolver resourceResolver; @PostConstruct protected void init() { Resource res = resourceResolver.getResource("/content/we-retail"); } }
If you are able to fetch siblings of current page, then same logic you can use for other pages as well as you already have a path. You can use ResourceResolver to get Page resource and use same logic.
resourceResolver.getResource(PAGE_PATH).adaptTo(Page.class);
To get siblings, you can just get Parent of a Page and then iterate child nodes as explained here
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/siblings/td-p/168892
how to use resourceresolver, I am getting null pointer exception while using this
resourceResolver.getResource(PAGE_PATH).adaptTo(Page.class);
@ScriptVariable
private ResourceResolver resourceResolver;
I have used it as above and getting null point exception.
Please confirm if resourceResolver is coming null or resourceResolver.getResource(PAGE_PATH)?
resourceResolver is coming null
Sample code from default project structure.
@Model(adaptables = Resource.class) public class HelloWorldModel { @SlingObject private ResourceResolver resourceResolver; @PostConstruct protected void init() { Resource res = resourceResolver.getResource("/content/we-retail"); } }
Once you get the Page object you can use this to get all the siblings of that page.
page.getParent().listChildren();
I don't have page object , I only have page path
As explained above, you can get Page object using this code.
resourceResolver.getResource(PAGE_PATH).adaptTo(Page.class);
Views
Likes
Replies
Views
Likes
Replies