Liquid, JavaScript, themes, sales channels
I'm trying to write a snippet to use in my product template to dynamically add common product text to my product pages.
When I do something like this it works fine:
{% if product.tag == LARGE %}
This text block for LARGE items will be added to the product page.
{% endif %}
However I need to match 2 tags... not one. And this is where I get lost.
I need something that operates like the following:
{% if product.tag contains LARGE and RED %}
This text block for LARGE and RED items will be added to the product page.
{% endif %}
{% if product.tag contains LARGE and BLUE %}
This text block for LARGE and BLUE items will be added to the product page.
{% endif %}
I know this code isn't correct (and I've tried a lot of variations on the above), but hopefully it gets across what I'm trying to accomplish enough that someone will be able to help me figure out how to write it properly.
Thanks!
– Ian
Solved! Go to the solution
This is an accepted solution.
Hello Ian,
Tyr this one
{% assign has_z = 0 %}
{% for tag in product.tags %}
{% if tag contains "RED" or "BLUE" %}
{% assign has_z = has_z | plus: 1 %}
{% endif %}
{% endfor %}
{% if has_z >= 1 %}
Your content goes here
{% endif %}
Thanks
This is an accepted solution.
Hello Ian,
Tyr this one
{% assign has_z = 0 %}
{% for tag in product.tags %}
{% if tag contains "RED" or "BLUE" %}
{% assign has_z = has_z | plus: 1 %}
{% endif %}
{% endfor %}
{% if has_z >= 1 %}
Your content goes here
{% endif %}
Thanks
Thanks for the response, Guleria.
The actual tags I'm using are 5 sets (for now) of multiple options (I'm working with a range of 2000 items)
PRINT, ORIGINAL
LARGE, SMALL
ON-WHITE, ON-GRAY
PENCIL, CHINA-MARKER, ACRYLIC-MARKER
RED, BLUE, WHITE, BLACK, YELLOW, GREEN
I need to populate common description text about the size, medium, paper, etc. depending on which of these tags are present. For example: A SMALL PRINT will return one block of text, where an ORIGINAL ON-GRAY will return a completely different block of text.
Same code will work. You have to just extend it a/to your requirement.
Cool cool cool... I'm going to give it a shot now and see if I can manage to flesh it out and not break it. 🤞😬🤞
After muddling around with it for a bit, I realized I also needed to verify the product type as well. I'm not sure the significance of the "has_z" but everything seems to operate fine without it. Here's what I ended up using and will iterate as needed.
{% for tag in product.tags %}
{% if tag contains "Black" and "China-Marker" and "On-White" %}
{% if product.type == "Original Art" %}
Common description text for Black, China Marker, On White, Original Art.
{% endif %}
{% endif %}
{% endfor %}
Thanks for your help, Guleria!
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024