How to check the size of list in sightly? | Community
Skip to main content
Dinu_Arya
Level 6
Oct 16, 2015 2:28 AM UTC
Solved

How to check the size of list in sightly?

[Thread Edited By Adobe]

/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here. 

Go ahead and to it now: https://adobe.ly/3eDnB4v */

 

Actual Post:

Hi,

I need to check size of the list in sightly. I need to display UI only when it has more than 2 items in list. Any idea?

Thanks,

Arya.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:28 AM UTC

Depending on the methods of your list-object you can do something like this:

<div data-sly-test="${yourList.size > 2}">

...

</div>

16 replies

Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:28 AM UTC

Depending on the methods of your list-object you can do something like this:

<div data-sly-test="${yourList.size > 2}">

...

</div>

Translate
Dinu_Arya
Dinu_AryaAuthor
Level 6
Oct 16, 2015 2:28 AM UTC

Hi Feike,

Thanks. I have gone through sightly tutorials. But I didn't find this attribute. Actually we have size() for java.util.ArrayList. Can I use all of List methods like mylist.<ListMethod> ? Where can I find these tutorials? I have seen only count,first,last,index etc.

 

Thanks,

Arya.

Translate
Parth_Sahu
Employee
Apr 6, 2021 4:16 PM UTC

testing if I can comment!!

Translate
Feike_Visser1
Employee
Oct 16, 2015 2:28 AM UTC

hi arya,

You can just the methods from the object, whether that is List, Array etc.

So if you have .size(), you can use .size. If you have .length() or .count(). You can use .length or .count.

Hope this helps.

Inside your list, you can use things like ${itemList.count}, but this only works inside data-sly-list:

<ul data-sly-list="${currentPage.listChildren}">

<li>${item.name} Page ${itemList.index} of ${itemList.count}</li>

</ul> 

--
Feike

Translate
Parth_Sahu
Employee
Mar 21, 2020 8:55 PM UTC
".size" works for List Objects
Translate