Skip to main content
Contributor I
June 9, 2023
Solved

Using Shopify Tags in a Template

  • June 9, 2023
  • 1 reply
  • 308 views

Hi guys,

I've got a tricky use-case where essentially we're tagging customers using the Shopify Tags field with a "before" and "after" size after they take a quiz.

E.g.
Before Size: 10
After Size: 12

Syncs to Klaviyo fine - but I'm wondering how to extract a particular tag?

e.g. loop through the tags, and if a tag contains “Before Size” or “After Size”, extract it.

Once we extract the tag, can use a slice filter, I assume, to remove the "Before Size:" bit?

The tag may not always be in a fixed position in the index/array of tags, either - so can’t use a hardcoded index number.

Any advice welcome!

    This topic has been closed for replies.
    Best answer by bsck_dev

    Ah! Have solved it - I can loop through the tags and use an if + in statement: 

    {% for tag in person|lookup:'Shopify Tags' %}
    {% if "After Size" in tag %}
    Your new size: {{tag |slice:'13:15'}}</a>
    {%endif%}
    {% endfor %}

     

    Not sure if it’s the best way, but it works! 

    1 reply

    bsck_devAuthorAnswer
    Contributor I
    June 9, 2023

    Ah! Have solved it - I can loop through the tags and use an if + in statement: 

    {% for tag in person|lookup:'Shopify Tags' %}
    {% if "After Size" in tag %}
    Your new size: {{tag |slice:'13:15'}}</a>
    {%endif%}
    {% endfor %}

     

    Not sure if it’s the best way, but it works!