Last active
December 22, 2015 15:29
-
-
Save UberNick/6492960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@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