


This is the hierarchy of the page located under /content.
Now there's a property fileReference in the cq:featuredImage node and I want to fetch it in the sling model. How do I do it.
As mentioned by @AvinashGupta01 I've used the following piece of code to fetch the page title.
PageManager pm = resource.getResourceResolver().adaptTo(PageManager.class);
Page containingPage = pm.getContainingPage(resourceResolver.getResource(pagePath));
ValueMap pageProperties = containingPage.getProperties();
String pageTitle= pageProperties.get("jcr:title", String.class);
Can someone help me fetch the fileReference property located in cq:featuredImage into my sling model?
Solved! Go to Solution.
Views
Replies
Total Likes
@arindam6600 : Please use the following lines of snippet to get the value of fileReference in the cq:featuredImage node along with the previous snippet of code:-
Resource featuredImageResource = containingPage.getContentResource("cq:featuredImage");
ValueMap properties = featuredImageResource.adaptTo(ValueMap.class);
String fileReference = properties.get("fileReference", String.class);
Try this snippet and let me know if you face any issue.
Hi @arindam6600 ,
Please refer this: https://github.com/adobe/aem-core-wcm-components/search?q=NN_PAGE_FEATURED_IMAGE
Hope that helps!
Regards,
Santosh
Views
Replies
Total Likes
Hi @SantoshSai ,
Thanks for the link, but I couldn't figure out much. Will it be possible for you to help me with the code snippet that I can put in my sling model?
Views
Replies
Total Likes
@arindam6600 : Please use the following lines of snippet to get the value of fileReference in the cq:featuredImage node along with the previous snippet of code:-
Resource featuredImageResource = containingPage.getContentResource("cq:featuredImage");
ValueMap properties = featuredImageResource.adaptTo(ValueMap.class);
String fileReference = properties.get("fileReference", String.class);
Try this snippet and let me know if you face any issue.
Hi @AvinashGupta01 , I tried with the above script but it just prints cq:featuredimage and not the path of the image although the path is shown when checked in crx. Please advice.
Views
Replies
Total Likes
@arindam6600 Can you share me the screenshot of the CRXDE which node and property you want to retrieve?
Hi @AvinashGupta01 thanks for the help. The above piece of code worked. I did some typo and hence it was throwing errors.
Views
Replies
Total Likes