Search code examples
javaaemsightly

Reference an experience fragment dynamically in AEM


Is there any way to reference and insert an experience fragment to an AEM page dynamically? Say I have a users page which displays user data and each user can create their own profile using experience fragments (including photos, videos, content fragments). When I go to the users page I pass a reference to the user experience fragment and the users page must render the experience fragment.


Solution

  • There are probably a lot of ways to achieve this. It mostly depends on how you plan to pass the reference to the user experience fragment (XF):

    1. Explicitely - using a parameter, ie: /user/<id>?xf=<path>
    2. Implicitely - using a convention based on the user path, ie: /home/users/.../xf

    You can have a component that renders this experience fragment in your page. Once you manage to determine the path of the experience fragment using one of the methods above, you can just include that: <sly data-sly-resource="${useObj.xfpath}"></sly>