Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How to get the properties of component added into child pages in its root page using sling model ?

Avatar

Level 2
 
6 Replies

Avatar

Community Advisor

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

 

Avatar

Level 2

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 cardsParent Page.png

2) child page (a complete blog)Child blog page 1.png

Avatar

Community Advisor

@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

Avatar

Level 2

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 .

Avatar

Community Advisor

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

Thanks,
Krishna

Avatar

Level 4

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