Reputation: 2053
I'm a complete newb to this so I apologize in advance. I've got an instance of CQ5 set up and I can't figure out how to access specific nodes. So say I have a component with the path: /project/components/content/leftsidebar but I want to access properties of another node here: /content/dam/campaign
I know the properties.get method works but only if your within that node properties.get("title", "placeholder");
I'm a complete newb so please post code samples were possible.
Thanks!
Upvotes: 2
Views: 9109
Reputation: 6744
You'd want to use the ResourceResolver
in order to get the resource that you're looking for. From there, you can adapt it to a ValueMap
& read its properties:
ResourceResolver resourceResolver = slingRequest.getResourceResolver();
Resource campaignResource = resourceResolver.getResource("/content/dam/campaign");
ValueMap campaignProperties = campaignResource.adaptTo(ValueMap.class);
String title = campaignProperties.get("title", "placeholder");
You can read more about accessing properties on the Apache Sling website. Remember, CQ5 is Sling under the hood, so it's a great resource & you're still a level of abstraction above accessing the JCR directly.
Upvotes: 5