Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

aem

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?

like image 275
user2630656 Avatar asked Sep 18 '13 11:09

user2630656


1 Answers

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();
like image 118
Tomek Rękawek Avatar answered Jan 01 '23 12:01

Tomek Rękawek