Solved

Can I skip repeating content with the Block Repeat Feature?

  • 15 September 2021
  • 3 replies
  • 11 views

Badge

I’m working on a new email for a Post-purchase workflow and would like to hide and show different modules based on what the customer purchased. I’ve looked into doing this with both the Block Repeat Feature and by writing my own code into my template. The one thing I’m stuck on is how to prevent the system from repeating the module if the customer has 2 or more of the same product in their purchase. For example, if they bought two candles, I want to show the “Candle Care” module 1 time, not twice. 

Does anyone know how to do this in the Block Repeat Feature or in custom liquid logic? Here is the liquid that I already tried but didn’t work:

{% for item in event.extra.line_items %}  {% if 'Candle' in item.name %}   {% firstof "true" as custom_candle_variable %}  {% elif 'Book' in item.name %}    {% firstof "true" as custom_book_variable %}  {% elif 'Trio' in item.name %}    {% firstof "true" as custom_trio_variable %}  {% endif %}{% endfor %}{% if custom_candle_variable %}  <!-- show Candle block here -->{% endif %}{% if custom_book_variable %}  <!-- show Book block here -->{% endif %}{% if custom_trio_variable %}  <!-- show Trio block here -->{% endif %}
icon

Best answer by Dov 17 September 2021, 16:04

View original

3 replies

Userlevel 6
Badge +5

Hello @TigerEmails,

To clarify, are you saying if two items contain the word “candle” at all, you’d only want to display one of those items? Or only hide if it’s the exact same item twice?

Badge

If two items contains the word “candle” I want it to display the module just 1 time instead of twice. Basically I’m trying to hide and show different educational modules based on what the customer purchased. For example, if they bought 2 candles and a book (even if they were different types of candles), I want them to see the candle educational module 1 time (not twice) + the book educational module. Let me know if that makes sense. Thank you!

Userlevel 6
Badge +5

Hi @TigerEmails,

I would try adding an “and” statement including the quantity: 

{% if 'Candle' in item.name and if item.quantity == 1 %}

If you’re looking for further assistance with custom coding templates, I recommend checking in with one of our partners or perhaps someone on here who is custom-code savvy can assist :)

Reply