在两个组中一次购买具有多个标签的过滤器

时间:2016-09-16 10:47:06

标签: shopify liquid

我有多个产品组织有标签,标签在多个产品中重复。该组织的设置如下:

首页产品

-tag1

-tag2

-tag3

户外产品

-tag4

-tag5

-tag6

液体,像这样:

<div class="home-products">
{% for tag in collection.all_tags %}
    {% assign tag_handle = tag | handle %}
    {% if tag_handle contains 'tag1' or tag_handle contains 'tag2' or tag_handle contains 'tag3' %}
        {% if current_tags contains tag %}
            <div class="tag--active">
                {% if tag_handle contains 'tag1' %}               
                    {{ tag | link_to_remove_tag: tag }}     
                {% elsif tag_handle contains 'tag2' %}                
                    {{ tag | link_to_remove_tag: tag }}     
                {% elsif tag_handle contains 'tag3' %}                
                    {{ tag | link_to_remove_tag: tag }} 
                {% endif %}             
            </div>
            {% else %}
            <div>
                {% comment %}
                    Use link_to_add_tag if you want to allow filtering
                    by multiple tags
                {% endcomment %}
                {% if tag_handle contains 'tag1' %}               
                    {{ tag | link_to_add_tag: tag }}    
                {% elsif tag_handle contains 'tag2' %}                
                    {{ tag | link_to_add_tag: tag }}    
                {% elsif tag_handle contains 'tag3' %}                
                    {{ tag | link_to_add_tag: tag }} 
                {% endif %} 
            </div>
        {% endif %}
    {% endif %}
{% endfor %}
</div>

<div class="personal-care-products">
{% for tag in collection.all_tags %}
    {% assign tag_handle = tag | handle %}
    {% if tag_handle contains 'tag4' or tag_handle contains 'tag5' or tag_handle contains 'tag6' %}
        {% if current_tags contains tag %}
            <div class="tag--active">
                {% if tag_handle contains 'tag4' %}               
                    {{ tag | link_to_remove_tag: tag }}     
                {% elsif tag_handle contains 'tag5' %}                
                    {{ tag | link_to_remove_tag: tag }}     
                {% elsif tag_handle contains 'tag6' %}                
                    {{ tag | link_to_remove_tag: tag }} 
                {% endif %}             
            </div>
            {% else %}
            <div>
                {% comment %}
                    Use link_to_add_tag if you want to allow filtering
                    by multiple tags
                {% endcomment %}
                {% if tag_handle contains 'tag4' %}               
                    {{ tag | link_to_add_tag: tag }}    
                {% elsif tag_handle contains 'tag5' %}                
                    {{ tag | link_to_add_tag: tag }}    
                {% elsif tag_handle contains 'tag6' %}                
                    {{ tag | link_to_add_tag: tag }} 
                {% endif %} 
            </div>
        {% endif %}
    {% endif %}
{% endfor %}
</div> 

我的问题是我希望每次在类别之间切换时“重置”。目前,如果你点击一对夫妇,然后从下一个,你得到

集合/所有/ TAG1 + TAG2 + tag5

什么时候应该

集合/所有/ tag5

思考?提前致谢

1 个答案:

答案 0 :(得分:0)

你的第二个循环是使用第一个循环修改的collection.all_tags数组。而是创建标签的副本。试试这个:

{% assign newArray = "" | split: ""  %}
{% assign tags = newArray | concat : collection.all_tags %}

{% for tag in tags %}
   ...Home Products...
{% endfor %}

{% for tag in collection.all_tags %}
   ...Outdoor Products...
{% endfor %}