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:
<div data-sly-use.contentJS="content.js">
${contentJS.parentPage.path}
</div>
use(function() {
return {
parentPage: currentPage.getAbsoluteParent(1)
};
});
You can dynamically determine the site root page in AEM based on the current page's location. You can achieve this by:
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.
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.
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
@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!
Views
Replies
Total Likes
Views
Like
Replies
Views
Likes
Replies
Views
Likes
Replies