Product Template Snippet Assistance: When a product contains these 2 tags > add this text

Solved
ianwarsenualt
Tourist
6 1 0

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

0 Likes
Guleria
Shopify Partner
1454 299 413

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

Want to modify or custom changes on store hire me.
Email: guleriathakur43@gmail.com, Skype: navrocks1
If helpful then please Like and Accept Solution.
0 Likes
ianwarsenualt
Tourist
6 1 0

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.

 

0 Likes
Guleria
Shopify Partner
1454 299 413

Same code will work. You have to just extend it a/to your requirement.

Want to modify or custom changes on store hire me.
Email: guleriathakur43@gmail.com, Skype: navrocks1
If helpful then please Like and Accept Solution.
0 Likes
ianwarsenualt
Tourist
6 1 0

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.

 

0 Likes
ianwarsenualt
Tourist
6 1 0

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!

0 Likes