OctoLion
OctoLion

Reputation: 11

Shopify / Liquid - Output order of product tags forloop seems random?

I have this is a shopify store but the order of the includes don't show up the way they are listed here. It goes.. carbon fibre, graph, compound. Does this have something to due with the includes? What am I missing?

   {% for tag in product.tags %}  
        {% if tag contains "Graph" %}
            {% include 'bow-graph' %}
        {% endif %}
        {% if tag == "Force Meter" %} 
            {% include 'power-meter' %}
        {% endif %}
        {% if tag contains 'Carbon' %} 
            {% include 'carbon-meter' %}
        {% endif %}
        {% if tag == "Touch Compound" %}
            {% include 'touch-compound' %}
        {% endif %}
    {% endfor %}

Upvotes: 1

Views: 490

Answers (2)

Rick Davies
Rick Davies

Reputation: 733

It has everything to do with the order in which tags are added to the product, they are not necessarily in any logical order (unless the administrator did that.) You are looping through them and your conditions are checking each tag in the order they were added to the product.

Upvotes: 0

NAVEKI
NAVEKI

Reputation: 11

Don't iterate over the tags, just simply put {% if products.tags includes '<string>' %} that may give you the order you are wanting

Upvotes: 1

Related Questions