Example of a simple Content Fragment and Experience Fragment creation and usage in AEM Front End (Sighly) code. | Community
Skip to main content
Level 8
March 21, 2026
Question

Example of a simple Content Fragment and Experience Fragment creation and usage in AEM Front End (Sighly) code.

  • March 21, 2026
  • 1 reply
  • 13 views

Hi all,

 

Kindly point me a to a tutorial for each of a simple Content Fragment and an Experience Fragment (with just two fields, say name and address)

  • Creation of Content/Experience Fragment Model
  • Creation of Content/Experience Fragment from it and populating the fields with values.
  • Process of Exposing it via GraphQL API
  • Any Sling Model required ? If so its Code.
  • Usage in AEM Front End (Sighly) with code..

 

I want to follow along this tutorial along and see this working.

 

A similar tutorial for Experience Fragment also will help.

 

Appreciate all your responses.

 

Thanks,

RK.

    1 reply

    AmitVishwakarma
    Community Advisor
    Community Advisor
    March 21, 2026

    Hi ​@nsvsrk 

    You won't find a single "CF + XF + GraphQL + HTL" tutorial in one place, but you can get exactly what you want by combining the standard headless tutorial with a tiny custom Sling Model + HTL. Below is a minimal "name + address" example you can follow.

    1. Simple Content Fragment example (name + address)

    1. Create the Content Fragment Model

    2. Create a Content Fragment instance

    • Go to Assets > Files, pick a folder under the configuration you enabled for headless.
    • Click Create > Content Fragment, choose the Person model.
    • Fill in:
      • name = "John Doe"
      • address = "221B Baker Street, London"

    2. Expose the Content Fragment via GraphQL

    1. Make sure GraphQL endpoints are enabled for your config (GraphQL + CF Models checkbox in the configuration).

    2. Open GraphiQL (AEM's built‑in GraphQL tool) and run a simple query like:

    query {
    personList {
    items {
    _path
    name
    address
    }
    }
    }

    You'll get JSON with name and address for your Person fragments.

    For a full end‑to‑end walkthrough (enable config, create models, create fragments, use GraphiQL, persisted queries, and a sample app), follow: https://experienceleague.adobe.com/en/docs/experience-manager-learn/getting-started-with-aem-headless/graphql/multi-step/overview

    3. Do you need a Sling Model? (for HTL usage inside AEM)

    • For pure headless / GraphQL: no Sling Model is needed; your client (React, SPA, etc.) calls GraphQL directly.
    • For usage inside an AEM Sites page (HTL): you typically:
      • either use the Core Content Fragment Component directly, or
      • write a simple Sling Model + HTL to read the fragment and print fields.

    Minimal Sling Model example

    package com.mysite.core.models;

    import com.adobe.cq.dam.cfm.ContentFragment;
    import org.apache.sling.api.resource.Resource;
    import org.apache.sling.models.annotations.DefaultInjectionStrategy;
    import org.apache.sling.models.annotations.Model;
    import org.apache.sling.models.annotations.injectorspecific.Self;

    import javax.annotation.PostConstruct;

    @Model(
    adaptables = Resource.class,
    defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
    )
    public class PersonCFModel {

    @Self
    private Resource resource;

    private String name;
    private String address;

    @PostConstruct
    protected void init() {
    ContentFragment fragment = resource.adaptTo(ContentFragment.class);
    if (fragment != null) {
    this.name = fragment.getElement("name").getContent();
    this.address = fragment.getElement("address").getContent();
    }
    }

    public String getName() {
    return name;
    }

    public String getAddress() {
    return address;
    }
    }

    In a real project this model is usually bound to the resource type of your custom component or to the CF component instance that points at a fragment.

     

    Simple HTL (Sightly) usage

    /apps/mysite/components/content/personcf/personcf.html:

    <sly data-sly-use.model="com.mysite.core.models.PersonCFModel">
    <div class="person">
    <p>Name: ${model.name}</p>
    <p>Address: ${model.address}</p>
    </div>
    </sly>

    Place this component on a page, make sure its resource points to the Person Content Fragment (for example via a dialog property), and HTL will render name and address.

    For more HTL patterns and a full sample project, see:https://experienceleague.adobe.com/en/docs/experience-manager-htl/content/code-samples

     

    4. Simple Experience Fragment example

    Experience Fragments are layout + components, not pure data like CFs. A minimal "name + address" XF looks like this:

    1. Create the Experience Fragment

    2. Use the Experience Fragment inside AEM Sites (HTL)

    • On a regular AEM Sites page, drag & drop the Experience Fragment core component.
    • Configure it to point to your XF and select a variation.
    • No extra Sling Model is required; the XF component renders the authored layout.

    3. Expose Experience Fragment for headless

    Amit Vishwakarma - Adobe Commerce Champion 2025 | 16x Adobe certified | 4x Adobe SME
    nsvsrkAuthor
    Level 8
    March 21, 2026

    Thanks ​@AmitVishwakarma.

    It is really a very detailed explanation.

     

    1.Kindly elaborate the steps in:

    Make sure GraphQL endpoints are enabled for your config (GraphQL + CF Models checkbox in the configuration).

    I went through your URL, but got lost in there.

     

    2.You are right in that a Sling Model is not required for consuming a Content Fragment.

    In such a case, how does the Sightly code look?

     

    3.For creating an Experience Fragment,  do we not need an Experience Fragment Model?

     

    ​​​​​​​4.For creating and consuming an Experience Fragment also if you could guide me step by step, the way you did for Content Fragments, I will be able to follow along and comprehend better.

     

    I highly appreciate all your guidance.

     

    Thanks,

    RK.