I want page.listChildren() to return only published pages | Community
Skip to main content
Level 4
October 25, 2022

I want page.listChildren() to return only published pages

  • October 25, 2022
  • 1 reply
  • 1602 views

Hi, I want a list of published pages so that I can use them further, 

Currently, I am using page.listChildren() it fulfill my purpose other but I only want the pages that are unpublished 

 

Can anyone help me out, please

Thank you

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Chandra_Hire
Level 4
October 25, 2022

Hi @rahul234dabas,

It can be done with below ways.

 

1. Sling API (com.day.cq.wcm.api.Page)

You can filter Iterator<Page> you are getting from page.listChildren() for unpublished pages, using existence of 'cq:lastReplicated' property on page. If this property exists it means page is published authorwise un-publised.  

 

ValueMap pageProperties = page.getProperties().

//Check the existence of 'cq:lastReplicated' and maitain collenction accordingly.

 

Please refer Page API - Page (The Adobe AEM Quickstart and Web Application.)

 

2. Using QueryBuilder API.

Create a query to filter the pages for non-existence of 'cq:lastReplicated' property and then iterate over the result.

 

Please refer (mainly Java snippet) -  Query Builder API | Adobe Experience Manager

 

Hope this helps

Magicr
Level 6
October 25, 2022

Another option is looking for property cq:replicationAction with value 'replicated'.

Chandra_Hire
Level 4
October 25, 2022

That's correct, it will be more optimal to use property cq:replicationAction (a small correction to check property value as 'Activate' for published page.)