I have a project path like /content/a/b/c
There are certain templates that I don't want to show for page paths having 'a' in it. So, I thought of using cq:allowedTemplates property.
The problem is that this property value is not getting inherited from the parent node to its child nodes.
What am I doing wrong here?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
The cq:allowedTemplates property is not inherited by default in AEM. It is only applicable to the node where it is set. If you want to restrict the templates for a specific path and its descendants, you need to set the cq:allowedTemplates property on each node individually.
you can try with some custom service.
The cq:allowedTemplates property is not inherited by default in AEM. It is only applicable to the node where it is set. If you want to restrict the templates for a specific path and its descendants, you need to set the cq:allowedTemplates property on each node individually.
you can try with some custom service.
In AEM, the cq:allowedTemplates property does not inherit to child nodes by design. This is because every page might need to have different allowed template options depending on its function.
If you're looking to inherit cq:allowedTemplates from the parent node, you may need to implement custom logic possibly using a Sling Model or Workflow. This logic will read the parent's cq:allowedTemplates property and apply it to the child page. This custom solution would need careful planning and testing to avoid any potential issues.
Sample code:
Register an Event Handler that listens for node added events in the content path.
@Component( service = ResourceChangeListener.class, property = { ResourceChangeListener.CHANGES + "=ADDED", ResourceChangeListener.PATHS + "=/content/a" } ) public class TemplateInheritingListener implements ResourceChangeListener{
}
Then create a method like Onchange:
@Override
public void onChange(List<ResourceChange> changes) {
for(ResourceChange change : changes) {
Resource addedResource = resourceResolver.getResource(change.getPath());
if(!addedResource.hasProperty("cq:allowedTemplates")){
Resource parent = addedResource.getParent();
if(parent.hasProperty("cq:allowedTemplates")){
String[] parentTemplates = parent.getProperty("cq:allowedTemplates");
addedResource.setProperty("cq:allowedTemplates", parentTemplates);
}
}
}
}
Thanks,
Venkat
@goyalkritika Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies