accessing nodes of NodeIterator through sightly | Community
Skip to main content
Level 3
Nov 17, 2015 1:07 PM UTC
Solved

accessing nodes of NodeIterator through sightly

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Nov 17, 2015 1:13 PM UTC

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

4 replies

akashs51893872
Level 3
Aug 10, 2018 7:51 AM UTC

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...

Translate
Level 3
Nov 18, 2015 4:56 AM UTC

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

Translate
Lokesh_Shivalingaiah
Level 10
Nov 18, 2015 12:38 AM UTC

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

Translate
edubey
edubeyAccepted solution
Level 10
Nov 17, 2015 1:13 PM UTC

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

Translate