user2630656
user2630656

Reputation: 129

cq5 - livecopy - how to tell when a page is a live copy and finding the children of its parents

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?

Upvotes: 5

Views: 3348

Answers (1)

Tomek Rękawek
Tomek Rękawek

Reputation: 9304

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();

Upvotes: 7

Related Questions