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>
Solved! Go to Solution.
Views
Replies
Total Likes
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>
You can look to use the First N in array function ->
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>
@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.
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!
Views
Replies
Total Likes