Expand my Community achievements bar.

SOLVED

Not able to identify last item in list slightly

Avatar

Level 6

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 

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Can you please try below and see if this works.

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

 

View solution in original post

4 Replies

Avatar

Correct answer by
Level 2

Can you please try below and see if this works.

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

 

Avatar

Community Advisor

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.

Sady_Rifat_0-1685611220850.png

 

Avatar

Community Advisor

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