When I iterate content nodes of a page, I cannot find any structure contents in Dynamic Template. How can I read components in Dynamic Template of a page?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hello @fulongt37334138
If you are trying to identify that the resource is rendered from a template or a Page, then you can create a utility function like this
public static boolean isTemplateResource(Resource resource){
if (resource == null) {
return false;
}
String path = resource.getPath();
boolean isTemplatePath = (path.startsWith("/conf/") && path.contains("/settings/wcm/templates/"));
return resource instanceof TemplatedResource || isTemplatePath;
}
It would really be helpful, if you can help us understand the use-case. Just FYI, page and templates are tied via a cq:template property. See if that helps !
The content of cq:page does not contain information about structure (if you are referring to /conf/${project-name}/settings/wcm/templates/${template-name}/structure)
Can you please share some more insight about your business expectation, probably will able to help better.
Hi,
I don't understand why you need to read the structure of the template in your own code. In the majority of all cases it should be sufficient to let AEM drive the resolution of the components and just implement the rendering of these components.
Deducing the structure of the page (that means the component hierarchy) is non-trivial and I am not sure if there's an official API for it.
Hello @fulongt37334138
If you are trying to identify that the resource is rendered from a template or a Page, then you can create a utility function like this
public static boolean isTemplateResource(Resource resource){
if (resource == null) {
return false;
}
String path = resource.getPath();
boolean isTemplatePath = (path.startsWith("/conf/") && path.contains("/settings/wcm/templates/"));
return resource instanceof TemplatedResource || isTemplatePath;
}
It would really be helpful, if you can help us understand the use-case. Just FYI, page and templates are tied via a cq:template property. See if that helps !
Views
Likes
Replies