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

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
Level 6

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
Level 6

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.