Expand my Community achievements bar.

SOLVED

Not able to achieve inherited allowed templates in a project path

Avatar

Level 5

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?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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.

Avatar

Level 4

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

Avatar

Administrator

@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