Retrive image from the page properties | Adobe Higher Education
Skip to main content
Level 3
October 31, 2023

Retrive image from the page properties

Hi 
i want to have images that i have uploaded in my child page in page properties to be in my parent page
Below is code where i want title , desctiption and image from my child pages that i have added in page properties while child page creation.

here is my code snippet:

  List<ExistingPagesModel> pagesList = new ArrayList<>();
        Resource parentResource = resourceResolver.getResource("/content/us/en/home/test");

        if (parentResource != null) {
            Iterator<Resource> childResources = parentResource.listChildren();
            log.info("childResources: {}");

            while (childResources.hasNext()) {
                Resource childResource = childResources.next();
                log.info("Processing child resource: {}", childResource.getPath());

                // Get property values from child resource
                childTitle = childResource.getValueMap().get("jcr:content/jcr:title", String.class);
                childDescription = childResource.getValueMap().get("jcr:content/jcr:description", String.class);
                String childImage = childResource.getValueMap().get("cq:featuredimage/fileReference", String.class);

                // childImage = getChildImageFromResource(childResource);

                log.info("Child Title: {}", childTitle);
                log.info("Child Description: {}", childDescription);
                log.info("childImage: {}", childImage);
                if (childTitle != null) {
                    // Create an ExistingPagesModel object for each child page
                    ExistingPagesModel pageInfo = childResource.adaptTo(ExistingPagesModel.class);
                    if (pageInfo != null) {
                        pageInfo.setChildTitle(childTitle);
                        pageInfo.setChildDescription(childDescription);
                        pageInfo.setChildImage(childImage);
                        pagesList.add(pageInfo);
                    }
                }
            }
        }
        log.info("pageInfo: {}", pagesList);
        return pagesList;
    }



title and description are working but in childImage i am getting null can someone help me with that?




Ce sujet a été fermé aux réponses.

1 commentaire

ShaileshBassi
Community Advisor
Community Advisor
November 3, 2023

Hi @tatrived Can you share the content.xml file screenshot how the content is saved on your page. As the property name has to be matched while retrieving the filereference.

Thanks,

Shailesh

tatrivedAuteur
Level 3
November 6, 2023

I am calling this in html file