Not able to identify last item in list slightly | Community
Skip to main content
manikanthar1295
Level 5
June 1, 2023
Solved

Not able to identify last item in list slightly

  • June 1, 2023
  • 3 replies
  • 1713 views

Hi 

I have the Sling model in that i have list like below 

public List<customList> getCustomProducts() {
return customProducts;
}

 

When i tried to identify the last item of list like below

 

<sly data-sly-list.product="${productModel.customProducts}">
<a href="${product.link}"><strong> ${product.name}</strong> </a>

<sly data-sly-test="${!product.last}">
<span class="separator">|</span>
</sly>

</sly>

in above code  <span class="separator">|</span> is printing for last item as well

 

if list contains 3 items the | should print 2 times like below

product1 | product2 | product 3 

 

But its printing like 

product1 | product2 | product 3 |

 

can some help me how to identify the last item from list so that or how i can achieve this 

 

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 yuvinitj

Can you please try below and see if this works.

<sly data-sly-test="${!productList.last}"> <span class="separator">|</span> </sly>

 

3 replies

yuvinitjAccepted solution
Level 2
June 1, 2023

Can you please try below and see if this works.

<sly data-sly-test="${!productList.last}"> <span class="separator">|</span> </sly>

 

manikanthar1295
Level 5
June 1, 2023

Thanks @yuvinitj 

 

Its working now.

Sady_Rifat
Community Advisor
Community Advisor
June 1, 2023

Hello @manikanthar1295 ,
You need to use List keyword after the object(product) name. then it will be productList. https://www.aemtutorial.info/p/htl-sly-list.html 

 

BTW you can also use the following properties if you need.

 

Shiv_Prakash_Patel
Community Advisor
Community Advisor
June 1, 2023

Hi @manikanthar1295 ,

You can use last property as below.

 

<ul data-sly-list="${currentPage.listChildren}"> <li data-sly-test="${itemList.last}">${item.title}</li> </ul>

 

Please check below for more details in HTL.

https://www.aemtutorial.info/p/htl-home.html

https://www.aemtutorial.info/p/htl-sly-list.html

Regards,

Shiv

Shiv Prakash