I have a footer element which needs to be shared. My plan is to set up the footer on the parent/home page but allow child pages to overwrite those properties.
I first look on the current component for the property (pretty standard), after that I get the path to the parent page to look for the property on the component with the same name.
function getProperty(property, currentPage) {
var val = null,
page = currentPage,
rootPage = page.getAbsoluteParent(2);
var curNode = currentNode.getPath(),
nodeStrIdx = curNode.indexOf("jcr:content"),
nodeStr = curNode.substr(nodeStrIdx + 12); // Remove 'jcr:content/' too
while(val == null) {
// If we've gone higher than the home page, return
if(page.getDepth() < 3) {
break;
}
// Get the same node on this page
var resource = page.getContentResource(nodeStr);
if(resource != null) {
var node = resource.adaptTo(Node.class); // *** This is null ***
// val = node.get(property);
}
// Get the parent page
page = page.getParent();
}
return val;
}
I've seen that you can change the type of the content resource to a node which should allow me to get the same property
but the resource.adaptTo(Node.class)
is returning null.
In case it's not clear, resource
is an absolute path to the node I want to pull the property from e.g. /content/jdf/en/resources/challenge-cards/jcr:content/footer/follow-us