How to allow some specific components inside a container component in AEM?
Few days back I was doing one POC on creating a specialised container component that will accept only some specific component inside it.
Earlier we used to do the same task with the help of /etc/design, after introduction of the policies in AEM we hava a totally different and easy way to handle the scenario.
Only limited article is available online on the same, that guides step by step.
Let’s discuss the policy first in AEM.
In AEM we have two types of policies in ui-app, one is for template and another is for component.
Template policies normally resides in /conf/your-project/settings/wcm/policies/wcm/foundation/components/responsivegrid path and component policies normally resides in /conf/your-project/settings/wcm/policies/your-project/components path if your component is structured like /apps/your-project/components/content in /apps .
Now coming to the implementation part.
I will be implementing it for only one template so it will be like that:
Every editable template is having structure as in below image
If you further expand the policies node the there will a common structure till
we will be further increasing the number of nodes under the root node to add the component path into it. After implementation new node structure will be like
Note: Every time whenever you add a component under the root node, its structure most be same as component is there in your project path for example if container component is on /apps/your-project/components/content/core/global/container-cutter/v1/container then in template also it will be /conf/your-project/settings/wcm/templates/landing-page/policies/jcr:content/root/responsivegrid/your-project/components/content/core/global/container-cutter/v1/container
Now on the component node two properties needs to added first cq:policy of string type with component policy path and sling:resourceType as string with wcm/core/components/policies/mapping as value.
Now as mentioned above, in the component policy path at /conf/your-project/settings/wcm/policies/your-project we can create same component path as project it is there in project like
for better management.
Now under the component node one nt:unstructured type nodes needs to be created with the some name for policy and with two properties one is components as multi string with allowed component path(s) and sling:resourceType as string with wcm/core/components/policy/policy. like
Note: If you see the components property, it is a multi string means you can allow more than one components as well but be careful while adding the paths.
If there is only one component then you can add path that starts with /apps/ but if more than one then paths starting with /apps/ will not work.
And there should not be any extra space in path string.
Please see the below .xmls.
Design dialog will also help here to accomplish the task from UI.
Hope this will help.