How to check the size of list in sightly? | Adobe Higher Education
Skip to main content
Dinu_Arya
Level 6
October 16, 2015
해결됨

How to check the size of list in sightly?

  • October 16, 2015
  • 13 답변들
  • 40497 조회

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

이 주제는 답변이 닫혔습니다.
최고의 답변: 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 답변

Level 3
September 18, 2017

// The WCMUse class' method that gives me an ArrayList

public List<String> getAllColumns() {

  List<String> allColumns = new ArrayList<String>();

  for (int i = 1; i <= 10; i++) {

    allColumns.add("Test" + "-" + i);

  }

  return allColumns;

  }

 

  # sightly code that I am trying out ....

<sly data-sly-list.myList="${myWCMUseObject.allColumns}">

  <div data-sly-test="${myList.size > 5}" data-sly-unwrap>

  Heloo!!!!!

        </div>

</sly>

Level 2
December 8, 2022

<div data-sly-test="${myListList.size > 5}" data-sly-unwrap>

Give like the above it will work..

Feike_Visser1
Adobe Employee
Adobe Employee
September 18, 2017

Use: ${myWCMUseObject.allColumns.size}

April 13, 2023

We can create a variable like this if list size is small, e.g. total is a variable created here which can be used further where ever size is required we can use this total object

<sly data-sly-list.listObj="${object.mylist}">
          <sly data-sly-test="${listObjList.last}">
            <sly data-sly-test.total="${listObjList.count}" />
      </sly>
</sly>

for example if I need to test if size is 2. We can use statement like 

data-sly-test="${total>2}"