Expand my Community achievements bar.

SOLVED

Help with accessing arrays using sightly with index

Avatar

Level 3

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!

1 Accepted Solution

Avatar

Correct answer by
Level 8

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>

View solution in original post

3 Replies

Avatar

Correct answer by
Level 8

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>

Avatar

Level 10

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>

Avatar

Level 3

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.