Skip to main content
varunmitra
Adobe Employee
Adobe Employee
Jul 31, 2015 3:10 PM UTC

Is there a way to read out the site root page dynamically depending on the site the page is placed in?

Yes, you can easily access the website root with the help of Page object. You can directly call getAbsoluteParent method to access the root page at a level of your choice.

Code snippet for the component would look like:

Sightly HTML code snippet:

<div data-sly-use.contentJS="content.js">

    ${contentJS.parentPage.path}

    </div>

Content.js

use(function() {

    return {

      parentPage: currentPage.getAbsoluteParent(1)

     };

});

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

3 replies

AmitVishwakarma
Community Advisor
Community Advisor
Jan 18, 2025 5:44 AM UTC

You can dynamically determine the site root page in AEM based on the current page's location. You can achieve this by:

  1. Using AEM's Sling Models: You can create a model that adapts to the current request and retrieves the root page based on the page's path.

  2. Using the JCR Repository: Query the /content structure or use the sling:resourceType property to identify the root page dynamically.

Both approaches let you reference the site root without hardcoding the page path, making it adaptable to different sites.

Translate
Amit Vishwakarma - Adobe Commerce Champion 2025 | 17x Adobe certified | 6x Adobe SME
daniel-strmecki
Adobe Champion, Community Advisor, UG Leader
Adobe Champion, Community Advisor, UG Leader
Jan 18, 2025 8:45 PM UTC

Hi @varunmitra,

in Sling Models, if you use adapt from SlingHttpServletRequest then you can:

// Inject the current page @ScriptVariable private Page currentPage; // Get root parent page currentPage.getAbsoluteParent(1)

 

Hope this helps,

Daniel

Translate
kautuk_sahni
Level 9
Feb 10, 2025 2:10 PM UTC

@varunmitra Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Translate
Kautuk Sahni