Expand my Community achievements bar.

SOLVED

Fetch page properties

Avatar

Level 5

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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.

Avatar

Community Advisor

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