Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Multifield with path of the page access page property

Avatar

Level 3

Hi Team,

                 I have requirement  to add page path in multifield and using that page path to access the page properties in sightly.

anyone worked on such type of requirement.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @savi50 

 

 

You can write a sling model for this. Read the page path from the multifield into the sling model. Once you have the page path get it as a resource then adapt it to a Page object. With getProperties() method you can fetch the properties from a Page object.

Below piece of code might help you to get started.

Resource resource = resourceResolver.getResource(<PAGE_PATH_FROM_MULTIFIELD>;
Page page = resource.adaptTo(Page.class);
ValueMap pageProperties = page.getProperties();

  Thanks,

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @savi50 

 

 

You can write a sling model for this. Read the page path from the multifield into the sling model. Once you have the page path get it as a resource then adapt it to a Page object. With getProperties() method you can fetch the properties from a Page object.

Below piece of code might help you to get started.

Resource resource = resourceResolver.getResource(<PAGE_PATH_FROM_MULTIFIELD>;
Page page = resource.adaptTo(Page.class);
ValueMap pageProperties = page.getProperties();

  Thanks,