Two if conditions

Solved
New Member
10 0 0
Hi,
 
I would like the output the code to link to a related category but it has to go to the right gender (women's or men's) collection.
 
For example, a product can contain tags such as Gender_Women, Gender_Men, Subcategory_Sneakers. Each product also has a corresponding collection handle in place depending on the gender tag. For example: 'mens-sneakers' or 'womens-sneakers'. 
 
Here's my attempt which doesn't work:
                	{% if product.tag contains 'Gender_Men' %}{% assign prodGender = "mens-" %}{% endif %}
                	{% if product.tag contains 'Gender_Women' %}{% assign prodGender = "womens-" %}{% endif %}
                	{% for tag in product.tags %}
                		{% if product.tag contains 'Subcategory_' %}
                		<a href="/collections/{{prodGender}}{{ tag | remove: 'Subcategory_' | handleize }}">{{ tag | remove: 'Subcategory_'}}</a>
                		{% endif%}
                    {% endfor %}
It outputs nothing. I assume that my if logics don't work. 
 
Any advice is appreciated.
 
0 Likes
Highlighted

Success.

Shopify Expert
2000 80 1449

In your code I see this:

{% if product.tag

But this should be:

 

{% if product.tags

You've made that little oversight a few times but a quick one to fix.

Looking at the fixed entire block perhaps this is what you need.

 

{% if product.tags contains 'Gender_Men' %}{% assign prodGender = "mens-" %}{% endif %}
{% if product.tags contains 'Gender_Women' %}{% assign prodGender = "womens-" %}{% endif %}
{% for tag in product.tags %}
  {% if tag contains 'Subcategory_' %}
    <a href="/collections/{{prodGender}}{{ tag | remove: 'Subcategory_' | handleize }}">{{ tag | remove: 'Subcategory_'}}</a>
  {% endif %}
{% endfor %}
★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
New Member
10 0 0
That works! It's my first attempt in trying to write Shopify code and this is massively useful to know that my thinking isn't far off. I just need to review these little oversights. Thanks, @Jason for helping me.
0 Likes