Display TAGS on product page, and have those tags link to relevant COLLECTION page

Solved
Highlighted
New Member
1 0 0

I'm also having trouble with tags that have spaces. For example, I have a tag called kitchen + bar, which launches /collections/all/kitchen%20+%20bar, instead of /collections/all/kitchen-bar, which would work. I tried changing the tag to kitchen+bar, which launches /collections/all/kitchen+bar, but that didn't work either. Anyone know how to create linkable tags with spaces that work? Thanks!

 


@Printmyposters wrote:

Hmmm it seems this code does not work properly for tags with spaces in them. Is there a way to correct that?


@M07H3R5H1P wrote:

thank you. a little too advanced for me at the moment but i got a different technique to display them. 
I added this to my product template !

{% if product.tags.size > 0 %}
  <div class="product-single__tags">
    <p>
      Tags:
      {% for tag in product.tags %}
      {% assign tag_coll = '/collections/all/' | append: tag %}
        {{ tag | capitalize | link_to: tag_coll }}{% unless forloop.last %},{% endunless %}
      {% endfor %}
    </p>
  </div>
{% endif %}

 


 


 

0 Likes
Highlighted
Tourist
3 0 4

Taking a little bit of both pieces of code shared here I ended up with this solution which worked fine for me:

      <div class="product-tags">
      <p><strong>Product Attributes:</strong> 
      {% for tag in product.tags %}
      <a href="/collections/all/{{ tag | handleize }}">{{ tag }}{% unless forloop.last %},{% endunless %}</a>
      {% endfor %}
      </p>
      </div>
2 Likes
Highlighted
New Member
1 0 0

This go in the same Template ?

0 Likes
Highlighted
Tourist
3 0 4

Yes, it goes in Sections / product-template.liquid 

1 Like