Include new fields in Experience Fragment v2 | Community
Skip to main content
Joelcio
Level 2
May 13, 2025
Solved

Include new fields in Experience Fragment v2

  • May 13, 2025
  • 1 reply
  • 507 views

Good afternoon everyone!


I'm working with the Experience Fragment V2 lib and I need to include two new fields, one called "Id" and the other "Audience".

Both should appear in the "Experience Fragment options" dialog box.


Would you like some help or advice on how to do this?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SantoshSai

Hi @joelcio,

You need to customize the dialog of the component by overlaying it.

1. Overlay the Dialog

Copy the Experience Fragment V2 component from /apps/core to your project’s /apps/your-project/components/experiencefragment path:

/apps/core/components/experiencefragment/v2/experiencefragment → /apps/your-project/components/experiencefragment

Make sure you're copying the cq:dialog node from the experiencefragment component.

2. Modify the Dialog

In the cq:dialog XML (or .content.xml) file, locate the "Experience Fragment Options" tab. This typically uses a granite:Form with tabs and fields inside.

Add two new fields under the correct tab:

<id jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldLabel="Id" name="./id" /> <audience jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldLabel="Audience" name="./audience" />

Place these within the correct tab content node (likely named something like experienceFragmentOptions).

3. Save the Fields in the JCR

Ensure the name="./id" and name="./audience" attributes are used so values are persisted in the JCR under the component's content node.

4. Read the Values in the HTL or Java Model (Optional)

If you're rendering or using these fields on the frontend or backend, make sure to include them in the model:

@ValueMapValue private String id; @ValueMapValue private String audience;

And expose them via getter methods in your model.

Hope that helps!

1 reply

SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
May 13, 2025

Hi @joelcio,

You need to customize the dialog of the component by overlaying it.

1. Overlay the Dialog

Copy the Experience Fragment V2 component from /apps/core to your project’s /apps/your-project/components/experiencefragment path:

/apps/core/components/experiencefragment/v2/experiencefragment → /apps/your-project/components/experiencefragment

Make sure you're copying the cq:dialog node from the experiencefragment component.

2. Modify the Dialog

In the cq:dialog XML (or .content.xml) file, locate the "Experience Fragment Options" tab. This typically uses a granite:Form with tabs and fields inside.

Add two new fields under the correct tab:

<id jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldLabel="Id" name="./id" /> <audience jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldLabel="Audience" name="./audience" />

Place these within the correct tab content node (likely named something like experienceFragmentOptions).

3. Save the Fields in the JCR

Ensure the name="./id" and name="./audience" attributes are used so values are persisted in the JCR under the component's content node.

4. Read the Values in the HTL or Java Model (Optional)

If you're rendering or using these fields on the frontend or backend, make sure to include them in the model:

@ValueMapValue private String id; @ValueMapValue private String audience;

And expose them via getter methods in your model.

Hope that helps!
Santosh Sai
Joelcio
JoelcioAuthor
Level 2
May 14, 2025

Hi, @santoshsai !

Thanks for your help!

Your solution works well but I am work in Hedless model and my model.json doesn't brings the variations.

Could you help me with this problem?

Supriya_Savre
Level 4
May 20, 2025

Hi @santoshsai,

 

Coud you please help @joelcio with the follow up query?