Our setup has various websites and some of which are livecopies from the main site. We are trying to determine if the page we are on is a livecopy. If so try and get its parent and the children of the parents. This allows us to determine each pages siblings to then use how we want.
Is this easily achievable using cq?
Checking if the page is a live copy
You can use LiveRelationshipManager
, adaptable from resource resolver:
resourceResolver.adaptTo(LiveRelationshipManager.class)
It has method hasLiveRelationship
which will return true
if passed resource is a live copy of something other. You can invoke this method passing current component resource.
Parent and siblings
Use PageManager
and Page
methods:
// resource - current component resource
ResourceResolver resolver = resource.getResourceResolver();
PageManager pageManager = resolver.adaptTo(PageManager.class);
Page currentPage = pageManager.getContainingPage(resource);
Page parentPage = currentPage.getParent();
Iterator<Page> siblings = parentPage.listChildren();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With