Not able to achieve inherited allowed templates in a project path | Community
Skip to main content
Level 4
March 6, 2024
Solved

Not able to achieve inherited allowed templates in a project path

  • March 6, 2024
  • 3 replies
  • 665 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SureshDhulipudi

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.

3 replies

SureshDhulipudi
Community Advisor
SureshDhulipudiCommunity AdvisorAccepted solution
Community Advisor
March 6, 2024

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.

Level 4
March 6, 2024

Hi @goyalkritika 

 

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

kautuk_sahni
Community Manager
Community Manager
March 7, 2024

@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.

Kautuk Sahni