Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a node form currenPage in CQ5

Tags:

jcr

aem

I have a component that needs to fetch properties from another component on the same page.

Is there a way to get a component's NODE object from currentPage ?

I have the name of the node I need to fetch available in the code.

like image 563
Riju Mahna Avatar asked Dec 25 '22 16:12

Riju Mahna


1 Answers

Assuming the node you need is in Page/jcr:content/yournode:

the Page object has a method getContentResource() which returns you the jcr:content resource node by default. You can also use page.getContentResource("yournode") to get a specific node below jcr:content.

If your node, for some reason is sibling to jcr:content (it shouldn't btw), you can your iterate the children of a resource using resource.listChildren().

Remember, this is all Sling API, so you are managing resources, not nodes. You can get a JCR Node from a resource using resource.adaptTo(Node.class)

like image 86
santiagozky Avatar answered Jan 05 '23 08:01

santiagozky