Expand my Community achievements bar.

SOLVED

get value of index 2 in a Slightly list

Avatar

Level 6

I have list in Slightly. From the list i am trying to print only index =2. Can some one help me with this. Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 6

<div data-sly-list.tab="${nav.tabs}" data-sly-unwrap>
            <div data-sly-test="${tabList.index == 2}" data-sly-unwrap>
                <div class="${tabList.index}">Its two</div>
            </div>
        </div>

View solution in original post

5 Replies

Avatar

Level 3

Hi,

 Try something like this.

    
<dl data-sly-list="${currentPage.listChildren}">
    <dt>index: ${itemList.index}</dt>
    <dd>value: ${item.title}</dd>
</dl>

Code samples are intended for illustration purposes only

The following default variables are available within the scope of the list:

item: The current item in the iteration.

itemList: Object holding the following properties:

index: zero-based counter (0..length-1).

count: one-based counter (1..length).

firsttrue if the current item is the first item.

middletrue if the current item is neither the first nor the last item.

lasttrue if the current item is the last item.

oddtrue if index is odd.

eventrue if index is even.

Defining an identifier on the data-sly-list statement allows you to rename the itemList and item variables. itemwill become <variable> and itemList will become <variable>List.

    
<dl data-sly-list.child="${currentPage.listChildren}">
    <dt>index: ${childList.index}</dt>
    <dd>value: ${child.title}</dd>
</dl>

 

Thanks,

Shivamurthy Mn

Avatar

Level 6

thanks. Got it. I will post the solution early.

Avatar

Correct answer by
Level 6

<div data-sly-list.tab="${nav.tabs}" data-sly-unwrap>
            <div data-sly-test="${tabList.index == 2}" data-sly-unwrap>
                <div class="${tabList.index}">Its two</div>
            </div>
        </div>

Avatar

Employee

Shorter version.

<sly data-sly-list.tab="${nav.tabs}">
                <div data-sly-test="${tabList.index == 2}"  class="${tabList.index}">Its two</div>
 </sly>
 

Avatar

Level 2

<sly data-sly-list.hero="${model.heading}">
            <sly data-sly-test="${heroList.index == 2}" >
                <div class="${heroList.index}">your content is two</div>
            </sly>
        </sly>