When a snippet is rendered, how do we get the code in the snippet to work?

Hi Shopify fam!

Looking for some help here :slightly_smiling_face:

I’m trying to code a simple condition for product tags. If the product tag is in the cart, do something.

I added the code in the cart-item snippet file on lines 112-114:

However, I realized that when the snippet is rendered, my code is not executing. Cart-item is being rendered into the main-cart file:

What should I add or change so that the condition works when rendered? Thanks in advance!

Capitalization matters with tags. Can I see the tag you add to the product?

@SomeUsernameHe , sure, the tag’s text was copied and pasted so it can’t be wrong.

I believe the issue is related to how the snippet renders. When I copy all of the code from the cart-item snippet and paste it where it’s supposed to render, then it works. But I would like to know how to make it work through the render.

Try inserting

{% for item in cart.items %}

before

{% if item.product.tags ... %}

and then insert

{% endfor %}

after the

{% endif %}

@SomeUsernameHe Thanks for your help, unfortunately, it didn’t work either.