I have a unique requirement in AEM Cloud project to re-use the custom sling model with multiple custom components.
I created, tested this thoroughly and everything working as expected but want to make sure anyone else tried this approach before with AEM. I know this is little out of way implementation for custom component general structure. This project has huge number of components and this pattern helps me to avoid creating hundreds of component specific duplicate sling models as the properties are mostly same with different HTMLs. I don’t want to create as variants as they fall into different content groups for better authoring experience. Below is the scenario.
Sling Model:
standardContent.java with properties Title, Description, image, video, buttons
Component 1:
<div class="comp1" data-sly-use.model="com.project.core.models.standardContent">
// Component specific HTML based on DESIGN which is totally different behavior than comp 2 & 3
</div>
Component 2:
<div class="comp2" data-sly-use.model="com.project.core.models.**standardContent**">
// Component specific HTML based on DESIGN which is totally different behavior than comp 1 & 3
</div>
Component 3:
<div class="comp3" data-sly-use.model="com.project.core.models.standardContent">
// Component specific HTML based on DESIGN which is totally different behavior than comp 1 & 2
</div>