Skip to content

Instantly share code, notes, and snippets.

@VivekSaha
Created September 30, 2025 07:57
Show Gist options
  • Select an option

  • Save VivekSaha/9c362a5bc466f44c48519a26690182f7 to your computer and use it in GitHub Desktop.

Select an option

Save VivekSaha/9c362a5bc466f44c48519a26690182f7 to your computer and use it in GitHub Desktop.
AEM - Custom component with dialog in Code
Custom component with dialog:- Code
Step 1 - Create component folder "productdetails"
e.g:- ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\productdetails
Step 2 - Create a ".content.xml" file
e.g:- ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\productdetails\.content.xml
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="Product Details"
componentGroup="AEM Geeks - Content"/>
Step 3 - Create a .html file with the same name of component "productdetails.html"
e.g:- ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\productdetails\productdetails.html
<sly data-sly-use.templates="core/wcm/components/commons/v1/templates.html"/>
<div class="product-details" >
<h2>${properties.productTitle}</h2>
<h3>${properties.productSubTitle}</h3>
<p>${properties.productDescription}</p>
</div>
<sly data-sly-call="${templates.placeholder @ isEmpty = !properties.productTitle}" />
Step 4 - Create a folder under the component folder "_cq_dialog"
ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\productdetails\_cq_dialog
Then create a .content.xml
ui.apps\src\main\content\jcr_root\apps\aemgeeks\components\productdetails\_cq_dialog\.content.xml
e.g
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Properties"
sling:resourceType="cq/gui/components/authoring/dialog">
<content
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<heading
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Product Title"
name="./productTitle"/>
<subheading
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Product Sub Title"
name="./productSubTitle"/>
<description
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textarea"
fieldLabel="Product Description"
name="./productDescription"
rows="5"/>
</items>
</column>
</items>
</content>
</jcr:root>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment