d
Topic
RussCW Member
Posts:
23
6 days ago

{% if collection.tags does not contain tag %} ??? Is there a ' does not contain' in liquid?

Bit of a newbie to liquid. So, I have a sidebar on collection pages that uses tags to display a 'Categories' filter amongst other things. The code for the categories filter is as follows...

<h4>Categories</h4>
{% assign tags = settings.shop_by_categories | split: ',' %}   
<ul>          	     
	{% for filter1_c in tags %}
		{% assign tag = filter1_c | strip %}
		{% assign tag_value = tag | handleize %}
      	{% assign filter1tag = forloop.index | minus:1 %}
		{% assign filter1tagid = 2 | times : filter1tag %}
      
        {% if collection.tags contains tag %}
		<li>
			<input type="checkbox" value="{{ tag_value }}" id="fl1-{{filter1tagid}}" {% if current_tags contains tag %}checked{% endif %} />
			<label for="fl1-{{filter1tagid}}"><span><span></span></span>{{tag}}</label>
		</li>
  		{% endif %}
	{% endfor %}
</ul>

My problem is I'd like to hide this filter if a collection doesn't contain any of the stipulated tags. I can see that the liquid below shows the filter if the tag is found. I want to say if collection.tags doesn't contain tag hide the filter. Any ideas?

{% if collection.tags contains tag %}

Cheers Russ

i
Replies
RussCW Member
Posts:
23
6 days ago

So I've tried the following to no avail :/

{% if collection.tags contains tag %}
{% unless collection.tags != tag %}
		<li>
			<input type="checkbox" value="{{ tag_value }}" id="fl1-{{filter1tagid}}" {% if current_tags contains tag %}checked{% endif %} />
			<label for="fl1-{{filter1tagid}}"><span><span></span></span>{{tag}}</label>
		</li>
{% endunless %}
  		{% endif %}

 

Jason Shopify Expert freakdesign.com.au
Posts:
8225
6 days ago

If the collection has a tag:

{% if collection.tags contains tag %}
  do stuff!
{% endif %}

if the collection does not have a tag:

{% unless collection.tags contains tag %}
  do stuff!
{% endunless %}

or 

{% if collection.tags contains tag %}{% else %}
  do stuff!
{% endif %}

Not sure if that helps, but reply back if not.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
RussCW Member
Posts:
23
5 days ago

Hi Jason 

Thanks for you reply. I give it a go.