내 커뮤니티 업적 표시줄을 확대합니다.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
해결됨

How to pull child page content in parent page?

Avatar

Level 2

Hi , i am trying to build more complex aem components. Imagine we have a structure as below

Products(parent page)
    -Mobile (child page 1)
    -Tablet (child page 2)

I have a component in parent Products page with list items authored to names of child pages. Now when i click on Mobile i want the mobile page contents to be populated in the component. How to achieve this?

주제

토픽은 커뮤니티 콘텐츠를 분류하여 관련성 있는 콘텐츠를 찾는 데 도움이 됩니다.

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor

you can use Sling Parameterized option right - 

 

 

To pass parameters from HTL (HTML Template Language) to a Sling Model in Adobe Experience Manager (AEM), you can use data attributes in your HTL and retrieve them in the Sling Model using the @ScriptVariable or @RequestAttribute annotations.

 

HTL script sends parameters to the Sling Model - The model manipulates these parameters in its method and returns the result for display.

 

<sly data-sly-use.myModel="${'com.example.core.models.ParameterizedModel' @ myParameterOne='Hello', myParameterTwo='World'}"
data-sly-test.isReady="${myModel.isReady()}">

<p>
${myModel.value}
</p>

</sly>

<sly data-sly-use.placeholderTemplate="core/wcm/components/commons/v1/templates.html"
data-sly-call="${placeholderTemplate.placeholder @ isEmpty=!isReady}">
</sly>

https://experienceleague.adobe.com/en/docs/experience-manager-learn/cloud-service/developing/advance...

원본 게시물의 솔루션 보기

4 답변 개

Avatar

Community Advisor

Hi @Zendarkke 

How would you like to display the mobile or tablet content on the parent page?

Do you want to show the entire child page, or just specific sections like the title, description, etc.? If so, you can use the Sling Resource API to read the child page's content and display it.

Alternatively, you could fetch the full content using the mobile.content.html and render it on the client side.



Arun Patidar

Avatar

Level 2

I would like to pull the data from the components present in the child page and display it in my component in the homepage. Is there a way to do this without creating a content api?

Avatar

정확한 답변 작성자:
Community Advisor

you can use Sling Parameterized option right - 

 

 

To pass parameters from HTL (HTML Template Language) to a Sling Model in Adobe Experience Manager (AEM), you can use data attributes in your HTL and retrieve them in the Sling Model using the @ScriptVariable or @RequestAttribute annotations.

 

HTL script sends parameters to the Sling Model - The model manipulates these parameters in its method and returns the result for display.

 

<sly data-sly-use.myModel="${'com.example.core.models.ParameterizedModel' @ myParameterOne='Hello', myParameterTwo='World'}"
data-sly-test.isReady="${myModel.isReady()}">

<p>
${myModel.value}
</p>

</sly>

<sly data-sly-use.placeholderTemplate="core/wcm/components/commons/v1/templates.html"
data-sly-call="${placeholderTemplate.placeholder @ isEmpty=!isReady}">
</sly>

https://experienceleague.adobe.com/en/docs/experience-manager-learn/cloud-service/developing/advance...

Avatar

Level 5

@Zendarkke 
if we want to load data/content from child pages like from mobile or tablet - we need to create sling model to fetch the data and HTL to display it, but there will be ajax changes as well. check below codes . 

khamat_bn_1-1728403419060.png


and below is ajax code which is main 

khamat_bn_0-1728403348188.png