1

I created some pages with hierarchy like

  • Home page
    • Men
      • Watches
        • Smart watch
        • Analog watch
      • Shoes
        • Sports shoes
        • Formal shoes
    • Women
      • Watches
        • Smart watch
        • Analog watch
      • Shoes
        • Sports shoes
        • Formal shoes

How can I fetch current page, that is, 'Home page' into my sling model? Also how to get the childPages i.e 'Men' and 'Women', grandChildPages i.e 'Watches' and 'shoes' of both childPages, and grandGrandChildPages i.e 'Smart watch', 'Analog Watch', 'Sports shoes' and 'Formal shoes' in same sling model?

toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
  • Hi Kiara! Welcome to Stack Overflow. There's a number of ways this can be achieved using the Sling and/or AEM APIs. You could write a recursive method using [`Page`](https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/wcm/api/Page.html) or [`ResourceResolver`](https://sling.apache.org/apidocs/sling8/org/apache/sling/api/resource/ResourceResolver.html) under the hood. If you're struggling with the particulars, please edit the question and share the code you tried so far and we can have a look at what the missing bits are. – toniedzwiedz May 10 '20 at 17:26
  • If you're looking for a reference, the AEM Core components would be a good place to start. What you're describing seems very similar to the core [Navigation component](https://www.aemcomponents.dev/content/core-components-examples/library/templating/navigation.html). I'd consider reusing it before diving into a custom implementation. The documentation also has links to GitHub so you can have a look at how it works internally and use similar techniques if you really do need a custom one. – toniedzwiedz May 10 '20 at 17:28
  • I am new to this technology and not yet worked with ResourceResolver class. Can you tell me how can i fetch current page using ResourceResolver?? – Kiara Joseph May 11 '20 at 06:08
  • Please review the Navigation component above, you can see the actual Java code by going to the GitHub repository: https://github.com/adobe/aem-core-wcm-components/blob/f9faa9c3b21c245d920f59579b02b3d22719c758/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/NavigationImpl.java – ronnyfm May 12 '20 at 02:44

0 Answers0