0
votes

I'm trying to add text to my product template to show a 'range' tag applied in the settings.

I added the following liquid code to my product template and it displays all the tags that have been entered into the settings - so far so good.

What I'm trying to achieve (and am struggling with) is instead of outputting all the tags. I just want to show a single tag that the product has, i.e. if the product contains a tag that matches a tag in prodNames then display that.

{% if settings.sort-dropdown-b-check %} 
{% assign prodNames = settings.sort_b  | replace: ' ,', ',' | replace: ', ', ',' | split: ',' %}    

  {% for tag in prodNames %}   
      {{ tag }} 
  {% endfor %}

{% endif %}

Any help with this would be most appreciated.

Thanks, Ben

1

1 Answers

3
votes

Try using the contains operator:

{% for tag in prodNames %}   
  {% if product.tags contains tag %}
    {{ tag }}
  {% endif %}
{% endfor %}