Page template pre-filling content fragment components with content fragment data | Community
Skip to main content
wolle89581941
Level 2
January 24, 2024

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

  • January 24, 2024
  • 3 replies
  • 777 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
January 24, 2024

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.html) in the "initial content" section of your template https://experienceleague.adobe.com/docs/experience-manager-65/content/implementing/developing/platform/templates/page-templates-editable.html?lang=en#initial-content . 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/components/contentfragment.


Hope this helps.

Esteban Bustamante
Raja_Reddy
Community Advisor
Community Advisor
January 24, 2024

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/features/templates.html?lang=en 
https://experienceleague.adobe.com/docs/experience-manager-65/content/implementing/developing/extending-aem/customizing-content-fragments.html 

 

wolle89581941
Level 2
January 25, 2024

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

kautuk_sahni
Community Manager
Community Manager
January 30, 2024

@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