get value of index 2 in a Slightly list | Community
Skip to main content
manoj_devapath
Level 5
May 25, 2016
Solved

get value of index 2 in a Slightly list

  • May 25, 2016
  • 5 replies
  • 23155 views

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.

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 manoj_devapath

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

5 replies

Shivamurthy_MN
Level 2
May 25, 2016

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

manoj_devapath
Level 5
May 25, 2016

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

manoj_devapath
manoj_devapathAuthorAccepted solution
Level 5
May 25, 2016

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

Feike_Visser1
Adobe Employee
Adobe Employee
May 25, 2016

Shorter version.

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

Level 2
February 1, 2023

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