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

1

5

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?

Wisner answered 18/9, 2013 at 11:31 Comment(1)
I presume you mean programmatically? What version of CQ are you using btw?Ium
K
7

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();
Koreykorff answered 18/9, 2013 at 19:58 Comment(1)
Would these child pages themselves be the direct live copies of the parent? Or would I have to do some sort of manual check? Would prefer to find the parent page of a live copy page, and then find all live copy pages belonging to the parent.Wisner

© 2022 - 2024 — McMap. All rights reserved.