Conditional text in confirmation email showing up multiple times

Topic summary

  • Problem: In a Shopify order confirmation template (Liquid, Shopify’s templating language), instructional text tied to a product metafield (metafields are custom data fields) appears multiple times when several line items share specs.type == ‘Engine’ due to being inside a for loop over line_items.

  • Proposed fix: Insert a break inside the if block so the loop stops after the first matching item. This prevents the instructional text from repeating.

  • Outcome: The original poster confirmed the break solution resolved the duplication.

  • New development: Another user applying break while displaying each item’s Product Type reports a different issue—after adding break, the first product’s type shows for all items instead of each item’s unique type. They attached a screenshot illustrating the mismatch and asked for guidance.

  • Status: Original duplication issue is resolved. The follow-up question about correctly rendering per-item Product Type without propagation remains open; no solution provided yet. The attached image is central to understanding the follow-up issue.

Summarized with AI on December 12. AI used: gpt-5.

I’m new to liquid, but managed to figure out how to display a chunk of instructional text in my confirmation emails depending on a specific product metafield value. The text is displaying for the appropriate metafield value, but I’m finding that the text displays multiple times if there are multiple products with the metafield. Is there a way to limit it so that the instructional text only displays once even if there are more than one products with the matching metafield value? Below is the current code.

{% for line in line_items %}
{% if line.product.metafields.specs.type == ‘Engine’ %}

// instructional text //

{% endif %}
{% endfor %}

Can you show us where the text is displayed, so we can get an idea how it looks and help you further?

Hey @smidge ! You should be able to add a break inside of your if statement, so that once the if statement is executed, the for loop will stop running. This should look something like the following:

{% for line in line_items %}
  {% if line.product.metafields.specs.type == 'Engine' %}

    // instructional text //

    {% break %}
  {% endif %}
{% endfor %}
1 Like

That worked like a charm, thank you so much!

Hi Brett- I am trying to input Product Type into my order confirmation emails and eventually my search led me to this thread. The {% break %} you suggested worked great for stopping the information from showing up multiple times but the first product type is showing up for each item in my confirmation email, instead of each item’s unique product type. Here is an example photo which shows the second item showing the product type of the first item when that is not it’s product type. Any suggestions?