Prerequisites
The following models for supporting the composite component use cases require the following prerequisites.
- Your AEM development instance is running locally on port 4502 with a sample project.
- You have a working external React app enabled for editing in AEM.
- The React app is loaded in the AEM editor using the RemotePage component.
Adding Composite Components to a SPA
There are three different models for implementing your composite component depending on your SPA implementation within AEM.
The following sections give examples of implementing each case using the card component as an example.
The component does not exist in your AEM project.
Start by creating the components that will make up the composite component, that is, components for the image and its text.
-
Create the text component in your AEM project.
-
Add the corresponding
resourceTypefrom the project in the component’seditConfignode.resourceType: 'wknd-spa/components/text' -
Use the
withMappablehelper to enable editing for the component.export const AEMText = withMappable(Text, TextEditConfig);
The text component is similar to the following.
If you create an image component in a similar way, you can then combine it with the AEMText component into a new card component, using the image and text components as children.
This resulting composite component can now be placed anywhere in the app and the will add placeholders for a text and an image component in the SPA Editor. In the sample below, the card component is added to the home component below the title.
This will display an empty placeholder for a text and an image in the editor. When entering values for these using the editor, they are stored at the specified page path that is, /content/wknd-spa/home at the root level with the names specified in itemPath.
The component exists in your AEM project but its required content does not.
In this case, the card component is already created in your AEM project containing title and image nodes. The child nodes (text and image) have the corresponding resource types.
You can then add it to your SPA and retrieve its content.
-
Create a corresponding component in the SPA for this. Ensure that the child components are mapped to their corresponding AEM resource types within the SPA project. In this example we use the same
AEMTextandAEMImagecomponents as detailed in the previous case. -
Since there is no content for the
imagecardcomponent, add the card to the page. Include the existing container from AEM in the SPA.- If there is a container already in the AEM project, we can include this in the SPA instead and add the component to the container from AEM instead.
- Ensure the card component is mapped to the corresponding resource type in the SPA.
-
Add the created
wknd-spa/components/imagecardcomponent to the allowed components for the container component in the page template.
Now the imagecard component can be directly added to the container in the AEM editor.
The component and its required content both exist in your AEM project.
If the content exists in AEM, it can be directly included in the SPA by providing the path to the content.
The AEMCard component is the same as defined in the previous use case. Here the content defined in the above location in the AEM project is included in the SPA.
Was this content helpful?
Announcements
Get hands-on with agentic AI.
Explore how AI agents work together through real examples and hands-on practice. Join your local User Group to design an agent workflow with your peers and leave with a practical framework you can apply to your own work.
Find an event