how to get page path and title of child and grand child pages in aem

Can anyone help?

I have a path of a root page and I want to retrieve all the child pages of root page and grandchild and grandchild of root page. My structure is like this


2 answers

  • answered 2021-02-19 05:58 Roger

    I think this should work.

    public static void visitRecursively(Node node, Session currentSession) {
        NodeIterator list = node.getNodes();
        while(list.hasNext())   {
          Node childNode = list.nextNode();
          // Verify child node for cqPage type
          if((childNode.hasProperty("jcr:primaryType")) && (childNode.getProperty("jcr:primaryType").getValue().getString()).equals("cq:Page") ){
            Node jcrNode = childNode.getNode("jcr:content");
            // Iterate some of the page properties
            String articleTitle="";String jcrDesc="";String jcrTitle="";String keywords="";
                articleTitle = jcrNode.getProperty("articleTitle").getString();
                jcrDesc = jcrNode.getProperty("jcr:description").getString();
                jcrTitle = jcrNode.getProperty("jcr:title").getString();
                keywords = jcrNode.getProperty("keywords").getString();
            String pagePropertiesString = "articleTitle--->"+articleTitle + "jcr:description--->"+jcrDesc+"jcr:title--->"+jcrTitle + "keywords--->"+keywords ;
"Page Properties :---> Node "+ childNode.getName()+ "Properties : " + pagePropertiesString );
      } catch (RepositoryException rpe){"Exception in recursive listing:");

  • answered 2021-02-23 18:50 Daniel Hernandez

    You can easily do this with SlingQuery

    final List<Resource> descendantPages = $(rootPage).("cq:Page").asList();


    or with a plain SQL2 query

    final String query = "SELECT page.* FROM [cq:PageContent] AS page "
        + "WHERE ISDESCENDANTNODE(page, '%s')";
    resolver.findResources(String.format(query, rootPage.getPath()), JCR_SQL2);

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum