As example we would like to include the Image Core Component two times in our component and display it in HTL.
For this we will need to create a dialog, sling model and HTL. We’d like to avoid as much copy paste as possible and keep our feet DRY.
The following snippets show you how to do this leveraging this feature.
Dialog
For the dialogs, we will need to include part of the core component’s image dialog in our own dialog.
CQ Template node
In order for the resource type core/wcm/components/image/v2/image to be added to the child node, we need to define the cq:template node under the component.
You can do this by creating a folder _cq_template with a .content.xml in that folder.
Put in the following contents:
Sling Model
We would like to include the core component Image two times in our sling model.
Once for displaying a default image and a different image when you are logged in.
These will be defined by the author
For our example we will use @ChildResourceFromRequest because the target model (Image) adapts from SlingHttpRequest only.
If you can adapt from Resource, you should use the @ChildResource annotation from Sling Models.
HTL
And in our HTL we can simply output our source using the javabean approach.