Help with accessing arrays using sightly with index | Community
Skip to main content
adobecq-venkat
New Participant
October 30, 2015
Solved

Help with accessing arrays using sightly with index

  • October 30, 2015
  • 3 replies
  • 3092 views

Hi,

I have 2 arrays question is multiitem and answer which is multi item again

I wanted to display answer under the question. I am trying to access question by index so that I can fetch corresponding answer

How can I do that with sightly?

<ul data-sly-list="${properties.question}">
  <li>${ [ item ]}</li>
</ul>

<ul data-sly-list="${properties.answer}">
  <li>${ [ item ]}</li>
</ul>

The above code displays all questions and displays all answers at the end of questions.

Thanks for your help!

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 leeasling

In your example, i'm pretty sure you can do something like this:

<ul data-sly-list="${properties.question}"> <li> Question: {item} Answer: ${properties.answer[itemList.index]} </li> </ul>

3 replies

adobecq-venkat
New Participant
October 30, 2015

leeasling wrote...

In your example, i'm pretty sure you can do something like this:

  1. <ul data-sly-list="${properties.question}">
  2. <li>
  3. Question: {item}
  4. Answer: ${properties.answer[itemList.index]}
  5. </li>
  6. </ul>

 

 It worked.Thanks for your answer.

smacdonald2008
New Participant
October 30, 2015

See this Sightly article - we handle a Java collection in Sightly:

Creating a Sightly and Sling Model DOM parser component

div data-sly-test="${properties.img=='true'}" data-sly-use.img="com.mycompany.myproject.components.Parser">
<b>Here are the Images</b>
    <ul data-sly-list="${img.images}">
       <li><img src="${item}"></li>
    </ul> 
</div>
leeaslingAccepted solution
New Participant
October 30, 2015

In your example, i'm pretty sure you can do something like this:

<ul data-sly-list="${properties.question}"> <li> Question: {item} Answer: ${properties.answer[itemList.index]} </li> </ul>