Limit "each" function for abandoned cart | Community
Skip to main content
Level 2
January 23, 2024
Solved

Limit "each" function for abandoned cart

  • January 23, 2024
  • 4 replies
  • 1155 views

I am using the "Each" function to create an email with the list of products that are left in the abandoned cart. The code already works this way but I need to limit it to bringing me a maximum of 5 products from the cart.

 

This is the code im using

 

<table>
<tbody>
{{#each context.journey.events.eventId.productListItems as |product|}}
<tr>
<td style="padding-right:20px;">
<img src="{{product.productImageUrl}}" height="150" width="150">
</td>
<td style="padding-right:10%;">
<b>{{product.name}}</b>
</td>
<td style="text-align:right;padding-right:20px;">
<b>${{product.priceTotal}}</b><br>
<p>
<a href="{{product.product}}">See product</a>.
</p>
</td>
</tr>
{{/each}}
</tbody>
</table>

 

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 narenmittapalli

Hi, try adding {%#if @index-1 < 6 %} inside the each function.

 

<table>
<tbody>
{{#each context.journey.events.eventId.productListItems as |product|}}

{%#if @index-1 < 5 %}
<tr>
<td style="padding-right:20px;">
<img src="{{product.productImageUrl}}" height="150" width="150">
</td>
<td style="padding-right:10%;">
<b>{{product.name}}</b>
</td>
<td style="text-align:right;padding-right:20px;">
<b>${{product.priceTotal}}</b><br>
<p>
<a href="{{product.product}}">See product</a>.
</p>
</td>
</tr>

{%/if%}
{{/each}}
</tbody>
</table>

4 replies

Adobe Employee
January 23, 2024
narenmittapalliAccepted solution
January 25, 2024

Hi, try adding {%#if @index-1 < 6 %} inside the each function.

 

<table>
<tbody>
{{#each context.journey.events.eventId.productListItems as |product|}}

{%#if @index-1 < 5 %}
<tr>
<td style="padding-right:20px;">
<img src="{{product.productImageUrl}}" height="150" width="150">
</td>
<td style="padding-right:10%;">
<b>{{product.name}}</b>
</td>
<td style="text-align:right;padding-right:20px;">
<b>${{product.priceTotal}}</b><br>
<p>
<a href="{{product.product}}">See product</a>.
</p>
</td>
</tr>

{%/if%}
{{/each}}
</tbody>
</table>

Adobe Employee
January 29, 2024

@sebastian_quevedo  I'll add that once you get the desired output make sure to save the result as an Expression Fragment so that you can easily re-use across channels and messages. 

Sukrity_Wadhwa
Community Manager
Community Manager
January 30, 2024

Hi @sebastian_quevedo,

Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!

Sukrity Wadhwa