Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

Fetch page properties

Avatar

Level 3

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.

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