accessing nodes of NodeIterator through sightly | Community
Skip to main content
November 17, 2015
Solved

accessing nodes of NodeIterator through sightly

  • November 17, 2015
  • 4 replies
  • 2831 views

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.
Best answer by edubey

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

edubey
edubeyAccepted solution
November 17, 2015

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

Lokesh_Shivalingaiah
November 18, 2015

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

November 18, 2015

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

akashs51893872
August 10, 2018

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