Expand my Community achievements bar.

Page template pre-filling content fragment components with content fragment data

Avatar

Level 2

Hi all,

 

I want to create a page template which contains one (or more) content fragment components. A user should be able to select a content fragment upon creation of a page and the content fragment component(s) get pre-filled with the data of the selected content fragment.

 

Which is the best way (best practice) to achieve this goal?

 

Thank you in advance!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

4 Replies

Avatar

Community Advisor

Hi,

You could add a 'Content Fragment' component from the core components (https://www.aemcomponents.dev/content/core-components-examples/library/core-content/content-fragment...) in the "initial content" section of your template https://experienceleague.adobe.com/docs/experience-manager-65/content/implementing/developing/platfo... . This component allows you to render your content fragment content. You can extend this component to achieve the desired look and feel. An example of how to do this can be found in the WKND site. You can use that project as a reference: https://github.com/adobe/aem-guides-wknd/tree/main/ui.apps/src/main/content/jcr_root/apps/wknd/compo....

EstebanBustamante_0-1706103634334.png


Hope this helps.



Esteban Bustamante

Avatar

Community Advisor

Hi @wolle89581941 

you can follow these steps:

  1. Create a page template that includes one or more content fragment components. This template will serve as the blueprint for the pages you want to create.

  2. Configure the content fragment component(s) to allow for pre-filling with data from a selected content fragment. This can be done by defining the appropriate properties and configurations for the component(s).

  3. When creating a new page based on the template, provide a way for the user to select a content fragment. This can be done through a dropdown menu, a search functionality, or any other suitable method.

  4. Once the user selects a content fragment, retrieve the data from the selected content fragment and pre-fill the content fragment component(s) on the page with this data. This can be done using the appropriate APIs or backend logic.

By following these steps, you can create a page template that allows users to select a content fragment and pre-fill the content fragment component(s) with the data from the selected content fragment.

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/sites/authoring/fea... 
https://experienceleague.adobe.com/docs/experience-manager-65/content/implementing/developing/extend... 

 



Avatar

Level 2

Hi,

 

My question was rather just about point (4.) in your answer. What are the appropriate APIs? Is there some sample code out there?

Because what I tried currently is just an ugly direct property manipulation on the CF component node after the user selected a content fragment. I wonder if there are better ways to do this?

 

Thanks and kind regards

Avatar

Administrator

@wolle89581941 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni