Fetch page properties | Community
Skip to main content
New Participant
November 8, 2022
Solved

Fetch page properties

  • November 8, 2022
  • 2 replies
  • 744 views

Hi all,

 

Scenario : In dialog when I put in the root path, the sling model will fetch the first 4 pages based on recent published date. So now I'm having the paths of the pages ready in the sling model with me. How to fetch some properties from those pages. Like my question is how do I use that path and get required properties of that page?

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

Hi @arindam6600 

 

Please use the below snippet of code. First, you would have to create  the page manager object and with that you can get the Page object by passing the page path. Once it's done, create the valuemap object and get the properties of the page.

 

  PageManager pm = resource.getResourceResolver().adaptTo(PageManager.class);

  Page containingPage = pm.getContainingPage(resourceResolver.getResource(pagePath));

  ValueMap pageProperties = containingPage.getProperties();

String prop= pageProperties.get("prop1", String.class);

 

Hope this helps.

2 replies

Mani_kumar_
New Participant
November 9, 2022

Hi 

Please find some of the examples to use the page properties and read from different objects in AEM

 

https://www.tabnine.com/code/java/methods/com.day.cq.wcm.api.Page/getProperties

Avinash_Gupta_
Avinash_Gupta_Accepted solution
New Participant
November 8, 2022

Hi @arindam6600 

 

Please use the below snippet of code. First, you would have to create  the page manager object and with that you can get the Page object by passing the page path. Once it's done, create the valuemap object and get the properties of the page.

 

  PageManager pm = resource.getResourceResolver().adaptTo(PageManager.class);

  Page containingPage = pm.getContainingPage(resourceResolver.getResource(pagePath));

  ValueMap pageProperties = containingPage.getProperties();

String prop= pageProperties.get("prop1", String.class);

 

Hope this helps.