How to read Dynamic Template structure content in Sling Model of a component using Java ?
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?
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?
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 !
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.