2016-09-16 54 views
1

我有多个产品组织标签和标签重复跨多个产品。该组织成立这样的:Shopify过滤器同时具有多个标签,两个组

首页产品

-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> 

我的问题是,我希望它“复位”每次类别之间切换。目前,如果一对夫妇从上一节,再一个从下一个点击,你会得到

集合/所有/标记1 +标记+ tag5

当它应该是

集合/所有/ tag5

想法?在此先感谢

回答

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 %} 
+0

谢谢,但我给了它一个镜头,它仍然没有工作,因为它仍然将两组视为一体。当我点击第2组中的标签时,它不会像我想要的那样清除并“重新开始”。 – Kevmon

+0

是的,看起来像'link_to_add_tag'在内部使用全局数组。 – jrbedard

+0

无赖。你认为还有另一种方法可以做到吗? – Kevmon