Highlighted

How to retrieve the node structure of the page in the UI giving the path of the page in aem6.3?

Malarvizhi_Sara

08-02-2018

I need to retrieve the internal node structure(which is nothing but including the node structure of how the components of the page are stored in the JCR) of the page and render the UI giving the path of the page in aem6.3. Can anyone help me out?

Replies

Highlighted

Hemant_arora

08-02-2018

Try this String nodePath = "/content/community-components/en"; try { Node node = null; NodeIterator nodes =null; String result=""; resource = slingRequest.getResourceResolver().getResource(nodePath);     if(resource != null)     {     node = resource.adaptTo(Node.class);     NodeIterator nodeItr = node.getNodes();             while(nodeItr.hasNext())                 {                 Node cNode = nodeItr.nextNode();                 result=node.getProperty("jcr:primaryType").getValue().getString();                 out.print(result);                 }     } } catch(Exception e) { out.print(e); } or http://keysandstrokes.info/aem-code-snippets-read-child-nodes-aem/

Highlighted

Malarvizhi_Sara

08-02-2018

Can you please let me know whether retrieval of the data in json format which is achieved using javascript use-api in aem6.3?

Highlighted

Hemant_arora

08-02-2018

use the below js to get page nodes use(function () { var pageName = currentPage.name; var title = currentPage.properties.get("jcr:title"); var resourceName = granite.resource.name; var resourceTitle = properties.get("jcr:title"); return { pageName: pageName, title: title, resourceName: resourceName, resourceTitle: resourceTitle }; }); refer to examples here https://helpx.adobe.com/experience-manager/htl/using/use-api-javascript.html

Highlighted

smacdonald2008

08-02-2018

What business case are you supporting with this information. Purhaps there is another way to achieve your  requirements.

Highlighted

aem_raw

08-02-2018

You can create the structure using  "infinity.json". For Example, if the page path is "/content/we-retail/ca/en/men" you can get the data from "/content/we-retail/ca/en/men.infinity.json" by using javascript(ajax call)

Highlighted

Malarvizhi_Sara

08-02-2018

Screen Shot 2018-02-09 at 11.49.34 AM.png

In the above image 'fr' is the page while giving the path of the page in the UI, it should retrieve the nodes and properties of them in a particular format(preferably in json), Is there anyways to do it using javascript use apis or anyother means?

Highlighted

jagjeetthukral

12-02-2018

Hi Malarvizhi Saravanan​ :

I would suggest you to use AEM's Content Services to achieve what you want.

I is the best solution to your problem, giving you granular control over the data you would like to expose via the API.

Cheers,

Jagjeet

AEM Forms Blog