Search code examples
reactjsaem

Is it possible to use React components to author AEM Experience Fragments, which then feed a headless frontend?


To briefly describe my goals --

  1. I have an external React component library of ~70 React components, which feeds a web frontend (Websphere Commerce site, which pulls in Experience Fragments via AJAX calls to get the fragment HTML), and also a React Native app. So for the web, AEM is basically the content engine which feeds our headless frontend.
  2. I'd like to use those same React components to feed the AEM Experience Fragment authoring experience, instead of having to rebuild each React component as an HTL template within AEM -- it's too much overhead to maintain a completely separate component library of HTL templates
  3. By following the official Adobe tutorial here, I see how it is possible to map React components to the Content Fragment authoring experience. By which I mean, if I go to AEM Home > Sites > (my site) > create a new fragment, the component I drag in is fed by a React template. I can tell, because the markup matches what is in my BasicComponent.js React template in ui.frontend, and not the basic-component.html template in ui.apps.
  4. But, if I go to AEM Home > Experience Fragments > create a new fragment, that same BasicComponent component will pull from the basic-component.html file in the component folder (next to .content.xml), instead of from BasicComponent.js

I'm new to AEM, so hopefully the above makes sense. I know I am missing something pretty fundamental re: how Experience Fragments differ from Content Fragments (if that is the right term). I've spent a lot of time Googling around for information, but I'm finding that my own ignorance is making it difficult for me to determine if what I'm reading is or is not a clue to solving my issue.

This is the repo that I pulled down to experiment with: https://github.com/drginm/aem-react-simple-example

Any help much appreciated! I'm sure I'm not the only AEM newbie looking for an approachable model for handling this situation.


Solution

  • Experience Fragments is not recommended used with ajax html in headless architecture, it should be exposed via sling model exporter in json format for the react consumption.

    To edit and modify the experience fragments AEM doesn't provide any APIs, AEM developer should give custom REST APIs to do the changes.

    I would recommend to go with the content fragments where the CRUD operation is possible via Assets api in AEM.

    References

    1. Difference between experience fragments and content fragments
    2. ASSETS API for the Content Fragments