Accepted Solutions (1)

Accepted Solutions (1)

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);
}

 

Answers (5)

Answers (5)

ChitraMadan

MVP

10-09-2020

Hi @maryanilak48011 ,

 

You can do something like below

 

@Getter
@Setter
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class SampleModel {
 
@SlingObject
private transient ResourceResolver resourceResolver;

@PostConstruct
public void init() {
 
Resource requiredResource = resourceResolver.getResource("path of the page");
String publicationDate =requiredResource.getValueMap().get("publicationDate", String.class);
 
}

maryanilak48011

11-09-2020

As per my requirement, I need to give the page path in the dialog, from that path, I'm fetching all the reference page properties like published date, Image from the reference page which I am giving in the dialog.

Shashi_Mulugu

MVP

10-09-2020

@maryanilak48011 thank you for posting in Communities.  Can you please explain your usecase a bit detailed?

 

I see that you want to fetch publishedDate property from a page into another page?

 

Is it just one property or do you need any other properties (set of properties) ?

 

Is it for direct rendering or any processing logic involved on top of property value?

 

If you have paths of the other pages handy in your current page, you can develop a sling model for the current page resource type and using Pagemanger api or resource api or node api, pass path of the pages in hand and get the properties, if there are multiple properties or any processing logic needed create a sling model for other as well and use adapto feature of resource to fetch values.

maryanilak48011

10-09-2020

But I need to fetch these values into the other page.