How can I get the publication date property and the Image property from this page in sling model
Solved! Go to Solution.
Views
Replies
Total Likes
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");
Views
Replies
Total Likes
Hi @maryani ,
You can do something like below
@maryani 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.
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");
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.
Views
Likes
Replies