Skip to main content
Problem Solver I
October 17, 2025
Solved

How can I output either the word "products" or the single product name?

  • October 17, 2025
  • 8 replies
  • 198 views

I’ve tried about every different iteration of this and I get “Your template contains placeholders we can't replace. No problem, de-select that option to view a preview.” when I try to preview

All of these output correctly as template tags if I remove the conditional

Doesn’t work

{% if event.extra.fulfillment.line_items|size > 1 %}products{% else %}{{ event.extra.fulfillment.line_items.0.name|default:'product' }}{% endif %}

 

Does work (outputs product’s name correctly)

{{ event.extra.fulfillment.line_items.0.name|default:'product' }}

    Best answer by theianjohnson

    That looks like it was actually a typo, but there still seems to be a bug. It’s the Shopify Delivered Shipment metric

     

    This works

    {% if event.extra.fulfillment.line_items|size == 1 %}{{ event.extra.fulfillment.line_items.0.name|default:'hat' }}{% else %}hats{% endif %}

     

    This does not work

    {% if event.extra.fulfillment.line_items|size > 1 %}hats{% else %}{{ event.extra.fulfillment.line_items.0.name|default:'hat' }}{% endif %}

    8 replies

    Problem Solver I
    October 17, 2025

    Adding to this, moving the conditional from > 1 to == 1 works

    {% if event.extra.fulfillment.line_items|size == 1 %}{{ event.extra.fulfillment.line_items.0.name|default:'hat' }}{% else %}hats{% endif %}

    ChristianPaget
    Klaviyo Employee
    Klaviyo Employee
    October 17, 2025

    Hi there,

    Is this the Shopify Fulfilled Order Metric? If so, it looks like you’re missing an “s” from fulfillment (should be fulfillments), and you also need to access the first item of fulfillments to get line_items, so it should look like this:

    {% if event.extra.fulfillments.0.line_items|size > 1 %}products{% else %}{{ event.extra.fulfillment.line_items.0.name|default:'product' }}{% endif %}

    If it’s not Shopify Fulfilled Order, could you send the event payload you are testing (minus identifying info) and the metric name?

    theianjohnsonAuthorAnswer
    Problem Solver I
    October 17, 2025

    That looks like it was actually a typo, but there still seems to be a bug. It’s the Shopify Delivered Shipment metric

     

    This works

    {% if event.extra.fulfillment.line_items|size == 1 %}{{ event.extra.fulfillment.line_items.0.name|default:'hat' }}{% else %}hats{% endif %}

     

    This does not work

    {% if event.extra.fulfillment.line_items|size > 1 %}hats{% else %}{{ event.extra.fulfillment.line_items.0.name|default:'hat' }}{% endif %}

    ChristianPaget
    Klaviyo Employee
    Klaviyo Employee
    October 17, 2025

    Hi there,

    Thank you for the clarification! Both of those snippets work in my testing for the Shopify Delivered Order Metric. What if you tried using the “Item Count” field instead of the size of the line_items array? So

    {% if event|lookup:’Item Count’ > 1 %}...{% endif %}
     

    Additionally, if you print the size of the line_items array under fulfillment, is it correctly outputting the length of the array? I would check that to see if it’s isolated to the ‘size’ function.

    Last piece,  you could try explicitly casting the output of size to an int by using floatadd:0:

    {% if event.extra.fulfillment.line_items|size|floatadd:0 > 1 %}…

    If none of those work, I can report this as a bug for our team to look into

    Problem Solver I
    October 17, 2025

    None of those work, all the same error (which is actually no error, I only see it because I opened up the dev console), this is all I see, it was super confusing

     

     

    I’m also editing a text only email in the source code which maybe is where the bug is here

    Byrne C
    Community Manager
    Community Manager
    October 24, 2025

    Hey ​@theianjohnson,

    I was thinking about an alternative option that might work. Would you mind trying this:

    {% if event.extra.fulfillment.line_items.1.name %}products{% else %}{{ event.extra.fulfillment.line_items.0.name|default:'product' }}{% endif %}

    I’m thinking that event.extra.fulfillment.line_items.1.name will only exist in the event data if there is a second product, so you can make that the if statement instead. The result would be that if there is a second product, the word “products” is displayed, where if there is no second product, the name of the first product is displayed instead. Let me know if this works!

    Problem Solver I
    October 28, 2025

    @Byrne C that’s what another community manager recommended and it does work, but there still seems to be a legitimate bug using the > or < sign in template tags. The work around was to use == or !=, but I think they’re still looking into it (I haven’t heard back in a few days)

    Byrne C
    Community Manager
    Community Manager
    November 3, 2025

    Hi ​@theianjohnson,

    Thanks for letting me know. I looked into the status of this issue, and can confirm that our engineering team knows about this, and fixing this is on our radar, though we don’t have a specific, expected completion date at the moment.