Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

0 Replies

Avatar

Level 2

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

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>