Expand my Community achievements bar.

Dive in, experiment, and see how our AI Assistant Content Accelerator can transform your workflows with personalized, efficient content solutions through our newly designed playground experience.
SOLVED

Limit "each" function for abandoned cart

Avatar

Level 2

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>

 

1 Accepted Solution

Avatar

Correct answer by
Level 1

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

 

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

{%#if @INDEX < 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>

View solution in original post

4 Replies

Avatar

Correct answer by
Level 1

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

 

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

{%#if @INDEX < 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>

Avatar

Employee Advisor

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

Avatar

Administrator

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