<%@include file="/libs/foundation/global.jsp" %> | |
<cq:include path="myComponent" resourceType="matelli/components/content/myComponent" /> | |
<% | |
/** Option 1: Simply direct reference */ | |
//String componentPath = "/content/myPage/jcr:content/myComponent"; //path to component | |
//Node node = resourceResolver.getResource(componentPath).adaptTo(Node.class); | |
//String title = node.getProperty("jcr:title").getString(); | |
//String text = node.getProperty("jcr:text").getString(); | |
/** Option 2: Direct reference, check for resource existence */ | |
//String componentPath = "/content/myPage/jcr:content/myComponent"; //path to component | |
//Resource myResource = resourceResolver.getResource(componentPath); | |
//String title = "", title = ""; | |
//if (!Resource.RESOURCE_TYPE_NON_EXISTING.equals(myResource.getResourceType())) { | |
// Node node = myResource.adaptTo(Node.class); | |
// title = node.getProperty("jcr:title").getString(); | |
// text = node.getProperty("jcr:text").getString(); | |
//} | |
/** Option 3: Page-relative reference */ | |
//Page myPage = currentPage; //reference to whatever page contains the component"; | |
//String componentPath = myPage.getPath() + "/jcr:content/myComponent"; //path to component | |
//String title = node.getProperty("jcr:title").getString(); | |
//String text = node.getProperty("jcr:text").getString(); | |
/** Option 4: Page-relative reference with getContentResource, and hasProperty check */ | |
Node node = currentPage.getContentResource("myComponent").adaptTo(Node.class); | |
String title = node.hasProperty("jcr:title") ? node.getProperty("jcr:title").getString() : "default title"; | |
String text = node.hasProperty("jcr:text") ? node.getProperty("jcr:text").getString() : "default text"; | |
%> | |
Component's title: <%= title %> <br/> | |
Component's text: <%= text %> <br/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment