current_tags
Product tags are used to filter a collection to only show products that contain a specific product tag. Similarly, article tags are used to filter a blog to only show products that contain a specific article tag. The current_tags variable is an array that contains all tags that are being used to filter a collection or blog.
In this article
Inside collection.liquid
Inside collection.liquid, current_tags
contains all product tags that are used to filter a collection.
The example below creates a list that displays every tag within every product in a collection. If the collection is filtered by the tag (i.e. if current_tags
does contain the tag), the link will remove the filter. If the collection is not currently filtered by the tag (if current_tags
does not contain the tag), a link will appear to allow the user to do so.
<ul>
{% for tag in collection.all_tags %}
{% if current_tags contains tag %}
<li class="active">{{ tag | link_to_remove_tag: tag }}</li>
{% else %}
<li>{{ tag | link_to_add_tag: tag }}</li>
{% endif %}
{% endfor %}
</ul>
Inside blog.liquid
Inside blog.liquid, current_tags
contains all article tags that are used to filter the blog.
The example below adds a breadcrumb that shows which article tag is being used to filter a blog. If there is a tag being used to filter a blog, the breadcrumb displays the tag name and provides a link back to the unfiltered blog.
{% if current_tags %}
<h1>{{ blog.title | link_to: blog.url }} » {{ current_tags.first }}</h1>
{% else %}
<h1>{{ blog.title }}</h1>
{% endif %}