Reuse Common Dialog Parts in AEM Components
Published
Reuse a Common Dialog As Is
apps / aem-demo / components / commons / color / .content.xml
<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="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<textColor jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/colorfield"
fieldLabel="Text Color"
name="./textColor"
showDefaultColors="{Boolean}true"
showProperties="{Boolean}true"
showSwatches="{Boolean}true"/>
<backgroundColor jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/colorfield"
fieldLabel="Background Color"
name="./backgroundColor"
showDefaultColors="{Boolean}true"
showProperties="{Boolean}true"
showSwatches="{Boolean}true"/>
</items>
</jcr:root>
apps / aem-demo / components / text / _cq_dialog / .content.xml
<textStyle jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/include"
path="/apps/aem-demo/components/commons/color"/>
color
dialog fragment as part of your component's dialog. Any updates in the shared dialog will automatically reflect in all components using it.Reuse a Common Dialog and Override or Extend certain Properties
sling:resourceSuperType
property to extend the common dialog and override the properties we need. Additionally, ensure that the sling:resourceType
matches that of the jcr:root
node in the common dialog.apps / aem-demo / components / text / _cq_dialog / .content.xml
<textStyle jcr:primaryType="nt:unstructured"
sling:resourceSuperType="/apps/aem-commons/components/commons/color"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<textColor jcr:primaryType="nt:unstructured"
name="./textColorV2"/>
<backgroundColor jcr:primaryType="nt:unstructured"
name="./backgroundColorV2""/>
</items>
</textStyle>
sling:resourceSuperType
property, we can inherit all the properties from the common dialog and override or add any additional fields as needed. This allows for maximum flexibility while still maintaining a clean and reusable dialog structure.