Fetch the date property from the page

Avatar

Avatar

maryanilak48011

Avatar

maryanilak48011

maryanilak48011

10-09-2020

How can I get the publication date property and the Image property from this page in sling model

maryanilak48011_0-1599753348441.png

 

View Entire Topic

Avatar

Avatar

raj_mandalapu

Avatar

raj_mandalapu

raj_mandalapu

10-09-2020

You need to handle multiple use cases and conditions

 

1. the direct approach is getting from the current page. inside the sling model, read publication date, and the Image property from the currentPage reference object.

2. if the current page object does not contain these properties, then check for the parent page.

 

But, your requirement is you need to fetch these values into the other page. the other page must know this page path.

1. if it is the parent page, then you can use currentPage.getAbsoluteParent() directly point to that page and read those properties.

2. if it is not the parent page, then the page must be authored somewhere, either in component or page properties of the other page.

3. In your sling model, read that page path and pass it to the getResource("page path");

@PostConstruct
public void init() {
Resource resourceresourceResolver.getResource("page path");
String pDate =resource.getValueMap().get("publicationDate"String.class);
}