data-sly-list check for the 2nd last item | Community
Skip to main content
Level 2
April 26, 2019
Solved

data-sly-list check for the 2nd last item

  • April 26, 2019
  • 1 reply
  • 4538 views

Based on HTL documentation HTL Block Statements

itemList: Object holding the following properties:

  • index: zero-based counter ( 0..length-1).
  • count: one-based counter ( 1..length).
  • first: true if the current item is the first item.
  • middle: true if the current item is neither the first nor the last item.
  • last: true if the current item is the last item.
  • odd: true if index is odd.
  • even: true if index is even.

data-sly-test="${itemList.last}" -> Check for the last item, however in my use case, I would need to check for the 2nd last item. Is there a ${itemList.count} in reverse order? In CSS, there is selector :nth-last-of-type(-n+2) for last 2 items.

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 Ravi_Pampana

For reversing the array list, we can use below in java and use the list in iterating.

Collections.reverse(arrayList)

I used above code in displaying last added property first in multi field

1 reply

Ravi_Pampana
Community Advisor
Ravi_PampanaCommunity AdvisorAccepted solution
Community Advisor
April 27, 2019

For reversing the array list, we can use below in java and use the list in iterating.

Collections.reverse(arrayList)

I used above code in displaying last added property first in multi field