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.
SOLVED

How to create Experience Fragment in AEM 6.5- React SPA

Avatar

Level 3

We have AEM project which was created with AEM architype 22 for AEM - React SPA.

In static templates we can use iParsys for inheriting any components to its child pages and also can cancel inheritance in page level.

As in newer AEM verison we are using Editable templates, and how do we achieve similar functionality?

I came to know that iParsys cant be used in Editable Templates and also not recommended.

I found reference for creating XF's but not for SPA.

 

Can someone please help on Creating XF's for AEM - React SPA?

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
5 Replies

Avatar

Correct answer by
Community Advisor

Avatar

Level 3

@Anudeep_Garnepudi  I have followed the same reference. Created a model, and component in React.
But I am not sure how to add experience fragment to a page and author it.

 

I have created a XF using web variation template and added a component.

Here I assume that we can just add the component and author. But, we cant preview it as the rendering will happen from react.

Later, in the page container I have added Experience Fragment container from General group and selected XF which I have created.

But, the added component is not getting displayed.

 

- Added a component and authored in Experience Fragment which was created using web variation template

papenaarun_3-1608636895132.png

 

- Experience Fragment container in page container

papenaarun_2-1608636820698.png

 

 

Avatar

Employee Advisor

@papenaarun 

Does your other react components (other than XF) render on this page? It's possible the react library is not available or the app is not initialized where you added the XF.

Avatar

Level 3

Yes, Other components which are created in React are loading without any issue.

In fact the XF for which I have created in React is loading but the components which are added not getting populated.

Check the React component for XF.

/*
ExperienceFragment.js

Maps to cq/experience-fragments/editor/components/experiencefragment
*/

import React from 'react';
import { MapTo, Container } from '@adobe/cq-react-editable-components';

/**
* Default Edit configuration for the Text component that interact with the Core ExperienceFragment component.
*
* @TyPe EditConfig
*/
const ExperienceFragmentConfig = {
emptyLabel: 'Experience Fragment',
isEmpty: function(props) {
var itemsOrder = props["cqItemsOrder"];
return !(itemsOrder && itemsOrder.length);

}

};

/**
* Text React component
*/
export default class ExperienceFragment extends Container {

render() {
console.log(JSON.stringify(this.props));
return (<div className="ExperienceFragment">
{this.childComponents}
</div>);
}
}

MapTo('cq/experience-fragments/editor/components/experiencefragment')(
ExperienceFragment,
ExperienceFragmentConfig
);

 

papenaarun_0-1608699597403.png


 
Updating Media