2016-09-16 58 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