How to get the properties of component added into child pages in its root page using sling model ? | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

DPrakashRaj
Community Advisor
Community Advisor
March 16, 2023

If you know what property you are looking for in side all the child pages, then make an aem query with that property, which will return all nodes within the root node and you can read those properties in root page sling model

 

Level 2
March 16, 2023

Use case is first I have to create 3-4 Blog Pages which will have a Blog Component, using this blog component i will add title, author name, and whole blog description, once i create all the child pages using Blog component, these all child pages will have a Parent Page, we have to fetch the Blog Component properties (title, authorName, short description) in parent page in a form of Blog Cards.

For understanding please check the attached images

1) Parent page with all blog cards

2) child page (a complete blog)

krishna_sai
Community Advisor
Community Advisor
March 16, 2023

@msgavali111 Using Querybuilder with the component's sling:resourceType you are looking for under rootpage, you will get the list of resources with which you can get hold of properties that you want.

 

 

path=rootPage property=sling:resourceType property.value=<component's resourceType that you are looking for> p.limit=-1

 

 


Hope this helps,
Krishna

Level 2
March 16, 2023

thank you so much @krishna_sai , i am trying to go with that approach only, actually i am fresher to in AEM, can you please check the above use case .

krishna_sai
Community Advisor
Community Advisor
March 16, 2023

@msgavali111 This works for your scenario. you can do this logic in your blog cards component slingmodel.

Thanks,
Krishna

Shivam153
Level 3
March 16, 2023

Hi @msgavali111 ,

You need to run a query through code where you will be providing the base path and resource type you are looking for. In your case, you want to take child pages so you can provide current Page path as base path. Take a reference of this--> https://aem.redquark.org/2018/10/day-17-working-with-query-builder-api.html

After you get the results, loop through the results and adapt it with resource and get required title, description, and other properties of component. In this way, you can achieve the functionality.

 

Thanks

Shivam