Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

accessing nodes of NodeIterator through sightly

Avatar

Level 3

Hi,

Is there any way to check NodeIterator hasNext() condition in sightly.
For instance:

Resource resource = resolver.getResource("/etc/xyz"); Node node = resource .adaptTo(Node.class); NodeIterator iterator = node .getNodes(); while (iterator.hasNext()) { Node child = iterator.nextNode(); }

Here I am getting NodeIterator from sightly helper class.Now in sightly html file I want to check hasNext() condition

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

In sightly file you cannot use java code like you are trying as they are .html files. You can do one thing, put all data in array then you can iterate the array in sightly file .

Here one sample @ https://helpx.adobe.com/experience-manager/using/domparser.html

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

In sightly file you cannot use java code like you are trying as they are .html files. You can do one thing, put all data in array then you can iterate the array in sightly file .

Here one sample @ https://helpx.adobe.com/experience-manager/using/domparser.html

Avatar

Level 10

did you try using 'data-sly-list' ??

Avatar

Level 3

Hi,

@edubey- I am placing my java code in sightly helper java class not in html files.

@bsloki- I worked with "data-sly-list" to iterate over the list of data.

But here I am trying to achieve "while condition' check through sightly syntax.

As we have couple of sightly blocking statements for if condition check(data-sly-test), etc.Similarly is there any way to check while condition.

Thanks,

swati

Avatar

Level 4

This might help:


<sly data-sly-list="${resource.listChildren}">
  <div data-sly-test="${item}">  <!-- this is something similar to hasNext() -->

     <!-- ONLY if there are items -->

  </div>
</sly>


Good Luck...