While working on a project, I came across a common requirement for a component which made me think for quite a while on how to best implement it. Since I can't be the only one who came across this, I’d like to share this use case with my view on the problem as well as two possible approaches, a direct approach to implementation and an alternative method I came up with.
Everything is available in a GitHub repository linked at the bottom, in case you would like to try it out for yourself.
Be aware: previous knowledge of Adobe Experience Manager (AEM) is required.
In this post, we will go over a use case for components that use properties from a resource somewhere else in the JCR tree. A common example is some kind of card component or an overview component that will show a small description of a page and that can be used as a link to this page. The component will point to the page and look up the information that needs to be rendered inside the component.
However, sometimes an author would like to defer from the general information pulled from this linked resource. The dialog of the component could be extended to add fields for the author to overwrite the information obtained from the original source.
The first approach
To solve the use case presented, the more direct approach to solve it in my opinion is to create the following building blocks:
- cq:Component under /apps