Solved

Limit displaying products from event to just 3

  • 31 July 2023
  • 1 reply
  • 61 views

Badge +3

Hello,

I am creating a flow email to send out to profiles after they fill out a quiz on our website with their recommended products. I have the following code snippet (below) to display the results in the email, however I would like to limit the number of results shown to just three. Does anybody know a way to edit the code to make this happen?

<table style="width: 100%; table-layout: fixed;">{% for pairGroup in event|lookup:'valueGrouped' %}
<tbody>
<tr>{% for item in pairGroup %}
<td style="width: fit-content; padding: 4px;"><a href="{{ item.url }}" style="display: flex; justify-content: center;"> <img style="width: fit-content; min-width: 100px; max-width: 300px; min-height: 100px; max-height: 300px; object-fit: cover;" src="{{ item.image }}" /> </a></td>
{% endfor %}</tr>
<tr>{% for item in pairGroup %}
<td style="width: fit-content; padding: 0 4px;">
<h3 style="font-size: 16px; margin: unset; text-align: center;">{{ item.title }}</h3>
</td>
{% endfor %}</tr>
<tr>{% for item in pairGroup %}
<td style="width: fit-content; padding: 0 4px; margin-bottom: 4px;">
<h3 style="font-size: 12px; margin: unset; text-align: center;">{{ item.price }}</h3>
</td>
{% endfor %}</tr>
<tr>{% for item in pairGroup %}
<td style="width: fit-content; padding: 4px;">
<div style="display: flex; justify-content: center;"><a href="{{ item.url }}" rel="noopener" style="text-decoration: none !important; color: #fff; background-color: #1d2a22 !important; padding: 10px !important; border-radius: 0px !important;" target="_blank">SHOP NOW</a></div>
</td>
{% endfor %}</tr>
{% endfor %}</tbody>
</table>

Many thanks!

Benji

icon

Best answer by retention 1 August 2023, 05:30

View original

1 reply

Userlevel 7
Badge +58

Hi @Benji at New Forest, welcome to the community!

If I understand you correctly, you want to show the first 3 items for each “pairGroup” if there are more than 3 items.  You can use the Filter “slice” command to limit it to 3 items like this:

 

{% for item in pairGroup|slice:’:3’ %}

 

You can read more about the “slice” command here in the official documentation:

 

 @Dov also answered something similar to this in this post:

Give that a try and see if that works for you.  

---

Joseph Hsieh // retentioncommerce.com // twitter: @retenion 

Reply