Skip to main content
Solved

Dynamic content | show or not show based on Shopify tags

  • March 20, 2026
  • 2 replies
  • 72 views

Forum|alt.badge.img

Hi all, 

I am struggling with dynamic content code. Support explained using this code underneath. But the problem is that people can buy a big suitcase and a small one at the same time. I need to prioritize the biggest size. How do I do this correctly? I want to do this in code with dynamic blocks instead of creating a split in my flow. Someone who can help or explain? Thanks! 

CODE:

{% with event.extra.line_items as items %}{% for item in items|slice:":1" %}{% if '55 cm' in item.name or 'Small' in item.name %}

your product block

{% endif %}{% endfor %}{% endwith %}

Best answer by ArpitBanjara

Hey ​@Isabellevandijk 

I think the problem with the original code is slice:":1". It only reads the first line item Shopify sends over, and Shopify doesn't guarantee any particular order. So if someone buys both a large and a small, you're basically rolling the dice on which one shows.

The fix is to scan all line items first, set flags, then render based on priority.

{% with event.extra.line_items as items %}

{% assign has_large = false %}
{% assign has_medium = false %}
{% assign has_small = false %}

{% for item in items %}
{% if '78 cm' in item.name or 'Large' in item.name %}
{% assign has_large = true %}
{% elsif '67 cm' in item.name or 'Medium' in item.name %}
{% assign has_medium = true %}
{% elsif '55 cm' in item.name or 'Small' in item.name %}
{% assign has_small = true %}
{% endif %}
{% endfor %}

{% if has_large %}

YOUR LARGE CONTENT BLOCK HERE

{% elsif has_medium %}

YOUR MEDIUM CONTENT BLOCK HERE

{% elsif has_small %}

YOUR SMALL CONTENT BLOCK HERE

{% endif %}

{% endwith %}

Two passes. First loop reads every line item and flips the right flag to true. Second block checks them top-down, large wins, always. Once a bigger size is found, everything below it gets ignored.

Just swap in your actual product names where I've used '78 cm' and 'Large'. If you only have two sizes, delete the medium block entirely.

One thing worth checking: make sure you're pulling item.name and not item.title or item.variant_title. Depending on how your Shopify products are set up, the size text might live in a different field. If the conditions aren't matching, that's usually why. Let me know if this works.

I hope this helps and thank you for sharing your question here in the community.

Cheers

Arpit

2 replies

ArpitBanjara
Principal User II
Forum|alt.badge.img+37
  • Principal User II
  • Answer
  • March 21, 2026

Hey ​@Isabellevandijk 

I think the problem with the original code is slice:":1". It only reads the first line item Shopify sends over, and Shopify doesn't guarantee any particular order. So if someone buys both a large and a small, you're basically rolling the dice on which one shows.

The fix is to scan all line items first, set flags, then render based on priority.

{% with event.extra.line_items as items %}

{% assign has_large = false %}
{% assign has_medium = false %}
{% assign has_small = false %}

{% for item in items %}
{% if '78 cm' in item.name or 'Large' in item.name %}
{% assign has_large = true %}
{% elsif '67 cm' in item.name or 'Medium' in item.name %}
{% assign has_medium = true %}
{% elsif '55 cm' in item.name or 'Small' in item.name %}
{% assign has_small = true %}
{% endif %}
{% endfor %}

{% if has_large %}

YOUR LARGE CONTENT BLOCK HERE

{% elsif has_medium %}

YOUR MEDIUM CONTENT BLOCK HERE

{% elsif has_small %}

YOUR SMALL CONTENT BLOCK HERE

{% endif %}

{% endwith %}

Two passes. First loop reads every line item and flips the right flag to true. Second block checks them top-down, large wins, always. Once a bigger size is found, everything below it gets ignored.

Just swap in your actual product names where I've used '78 cm' and 'Large'. If you only have two sizes, delete the medium block entirely.

One thing worth checking: make sure you're pulling item.name and not item.title or item.variant_title. Depending on how your Shopify products are set up, the size text might live in a different field. If the conditions aren't matching, that's usually why. Let me know if this works.

I hope this helps and thank you for sharing your question here in the community.

Cheers

Arpit


Forum|alt.badge.img

Thanks for your answer. I am going to try this and see i it works out!