Quote's of the day
"You never fail until you stop trying"
What is Sling Resource Merger?
- Sling Resource Merger is the hidden engine that makes AEM’s inheritance powerful.
- It allows developers to extend, reuse, and customize components efficiently — without touching the original ones.
⚙️ Where It Is Used in AEM
Sling Resorce Merger works :
When extending a component
a). What it is: Create a new component that inherits from an existing one.
b). How it works:Use
sling:resourceSuperType to point to the parent component. c). Key point: Only the parts you override (dialog, HTML) are changed; the rest comes from the parent via Sling Resource Merger.
🧩 Purpose:
- We have an existing component in our AEM project (not core, our own).
- We found that our new component will use 80% of the same fields.
- So, instead of copying everything, we decide to extend and customize it.
Note: Here, PersonalInfo is my existing component, and the existing fields are FirstName and SecondName.
Sling Model interface for the existing component.
Sling Model implementation class for the existing component.
This is HTL file
Step 1: Create a (PersonalInfoExtend) new Component & extend the existing component with sling:resourceSuperType Property.
com.adobe.aem.guides.wknd.core.models.- The
PersonalInfoExtendinterface extends another interface calledPersonalInfo. -
This means it inherits all methods from
PersonalInfo. Along with the inherited methods, it also adds two new methods:
-
getAge()→ to fetch or return the user’s age. -
getSalary()→ to fetch or return the user’s salary.
This approach helps in reusing existing functionality (fromPersonalInfo) and extending it with new fields without changing the original code.-
Step 3: Create a Sling Model implement class for the PersonalInfoExtend component.
In this example, we’ve created a class called
PersonalInfoExtendImpl inside the packagecom.adobe.aem.guides.wknd.core.models.
Explanation - This class implements the interface
PersonalInfoExtend— meaning it provides the actual logic (or data) for the methods defined in that interface. - It also extends another class,
PersonalInfoImpl, so it inherits all the existing properties and methods from it.
Step 4: Create an HTL file for the PersonalInfoExtend component.
This is an authoring field on the page.
No comments:
Post a Comment