Core components are ooob components that are shipped with aem and it is highly recommended to use them either as it is or by overlaying or extending them to speed up the over all component development process. To use core components we need to create proxy components in aem. In this tutorial i will show you how to create proxy component in aem and override core components by following all the best practices that adobe recommends for extending core components in aem.
In this tutorial i am going to extend core text component also known as rich text editor (RTE) as it is most widely and frequently used component that nearly caters all type of requirement associated with text editing and provide WYSIWYG (what you see is what you get) text-editing experience.
After completing this tutorial you will have clear understanding about:-
- What are proxy components in aem.
- How to create proxy components in aem.
- Modify proxy component Policy.
- Test Proxy Component.
What are proxy components in aem:-
The best part of using core components is that, they are version-able means when new version of aem comes it will not affect your current functionality. And if you want to use latest features available in new version you have to just change reference from old to new version of core components in your custom component. We will see all of this in detail in this tutorial.
The first question that comes in mind is what are proxy components or proxy patterns ? Why i should use them ? can’t i directly use components like i used to use foundation components earlier ?
The answer to all of these question is as by core components are hidden by default, you cannot use them directly. Core components are designed in such a way that it should be accessed using proxy components only. The advantage of adding one more layer of proxy components is that your core components will be as it is and you can refer to any version of core component just by changing sling:resourceSuperType to new version. It is neat , easy to read and very clean.
Below screenshot will provide you better understanding about how component implementation process is broken down in aem:-
Now let’s see how to create proxy components.
Create proxy components in aem:-
- Navigate to /apps/weretail/components/content/.
- Create a new node of type cq:Component. (This component is known as proxy component). Click on Save All.
- Add following properties to this node.
- sling:resourceSuperType –> String –> core/wcm/components/text/v1/text
- componentGroup –> String –> We.Retail (You can add your project specific group)
- jcr:title –> String –> Rich Text Editor (Your component title name)
- jcr:description –> String –> My Proxy Rich Text Editor Component (Your component Description)
- You can use this component now on both editable template and static template. For using it on we retail editable template. Follow below steps.
- Edit the template in http://localhost:4502/editor.html/conf/we-retail/settings/wcm/templates/hero-page/structure.html
- Edit the policy for the Layout Container
- Add your component to the list of allowed components. Click save on top right corner after making your changes.
- Go to http://localhost:4502/editor.html/content/we-retail/ca/en/men.html and try adding your component into the parsys.
That’s it, you have successfully created a proxy component. But its not all. I want to add just 1 more point. What new has been added to Rich Text component (RTE) as a part of core components . Earlier it was the responsibility of developer to provide what features an rte should have. But if you are using core components RTE then an author can decide what all features he want to see and what not. Let’s see how an author can do all of this.
Note:- The Core Components are not part of the AEM 6.3 installation, but you might find them installed since they are part of the We.Retail packages. If you use the production-ready “nosamplecontent” runmode they will not be installed. I recommend deploying them along your project packages.
Modify proxy component Policy:-
- Navigate to your editable template http://localhost:4502/editor.html/conf/we-retail/settings/wcm/templates/hero-page/structure.html.
- Select Layout Container of the template.
- Click on component policy icon which you wish to update.
- You will be navigated to component configuration page.
- You can create a new policy.
- Enter Policy Title – Enable RTE extra features (Your policy title)
- Enter Policy Description – This is RTE component policy.(Your policy description)
- From Right side column. Expand any tab like features and just select/unselect the checkbox. This will enable or disable particular feature from your proxy component(in our case RTE).
- Click save on top right corner and that’s it you are done.
See how easy it is now to enable or disable a particular feature for authors. If you are using core components in aem 6.3. You can achieve this using static template also, instead of component policy just go to design dialog of rte component and you will get same dialog to enable/disable the feature. But you have used foundation text component either from /libs/wcm/foundation/components/text or /libs/foundation/components/text, then author will not have this flexibility to enable to disable rte features.
Test Proxy Component:-
- Go to http://localhost:4502/editor.html/content/we-retail/ca/en/men.html
- Drag and drop your RTE component into parsys.
Hope you get a fair understanding of what proxy components are, why they are used and how to create/modify them. If you still face any issue just drop me a comment.
Click Here to download the Package