Skip to main content
Level 2
Jan 23, 2024 7:55 PM UTC
Solved

Limit "each" function for abandoned cart

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.
narenmittapalliAccepted solution
Jan 25, 2024 4:31 AM UTC

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

IvanMi1
Adobe Employee
Adobe Employee
Jan 23, 2024 10:06 PM UTC
narenmittapalliAccepted solution
Jan 25, 2024 4:31 AM UTC

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>

Translate
IvanMi1
Adobe Employee
Adobe Employee
Jan 29, 2024 7:56 PM UTC

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

Translate
Sukrity_Wadhwa
Level 4
Jan 30, 2024 7:02 AM UTC

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!

Translate
Sukrity Wadhwa