How to check the size of list in sightly? | Community
Skip to main content
Dinu_Arya
New Participant
October 16, 2015
Solved

How to check the size of list in sightly?

  • October 16, 2015
  • 13 replies
  • 40494 views

[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.
Best answer by Feike_Visser1

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

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

...

</div>

13 replies

Feike_Visser1
Feike_Visser1Accepted solution
Employee
October 16, 2015

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

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

...

</div>

Dinu_Arya
Dinu_AryaAuthor
New Participant
October 16, 2015

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.

Parth_Sahu
Employee
April 6, 2021

testing if I can comment!!

Feike_Visser1
Employee
October 16, 2015

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

Parth_Sahu
Employee
March 21, 2020
".size" works for List Objects