本文介绍了如果选择当前供应商,如何捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在收集页面和索引的侧边栏中,我列出了所有带有以下代码的供应商.现在我想选择了特定的供应商时,一个.主动类添加到.我想对产品类型列表做同样的事情.如何检查选择了哪个供应商?

In my sidebar on the collection pages and index, I have listed all vendors with the code below. Now I want to add an .active class to the <li> when that particular vendor is selected. I want to do the same thing with a list of product types. How do I check which vendor is selected?

我尝试了{% if collection.handle == vendor %}.但是它返回null,因为它只能捕获集合名称.

I tried {% if collection.handle == vendor %}. But it returns null as it can only capture collections names.

<ul class="nav">
  {% for vendor in shop.vendors %}
      <li class="collection-container {% if collection.handle == vendor %}active {% endif %}">{{ vendor | link_to_vendor }}</li>
  {% endfor %}
</ul>

请注意,URL构造为/collections/types?q = Nike,在=之后出现了供应商.我想尝试以某种方式捕获用户正在导航的当前集合,并在整个foreach循环中添加active标记.

Please note that the url is constructed as /collections/types?q=Nike and that after the = comes the vendor. I want to try to somehow capture on which current collection the user is navigating and add an active tag throughout the foreach loop.

我知道可以通过为每个供应商和产品类型创建集合并使用collection.handel来完成此操作,但是我有兴趣尝试通过捕获URL的最后一位来解决此问题.

I realise it can be done by creating collections for each vendor and product type and using collection.handel, but I am interested in trying to solve it by capturing the last bit of the URL.

推荐答案

**显示供应商过滤器使用以下代码**
<ul class="filter">
{%for shop.vendors%中的供应商}
{%,如果shop.vendors包含Vendor%}
{%,如果collection.current_vendor ==供应商%} <li class="active"> {{ link_to_vendor}} </li>
{%else%}
<li> {{供应商| link_to_vendor}} </li> {%endif%}
{%endif%}
{%endfor%}
</ul>

**show vendor filter use these code **
<ul class="filter">
{% for Vendor in shop.vendors %}
{% if shop.vendors contains Vendor %}
{% if collection.current_vendor == Vendor %} <li class="active"> {{ Vendor | link_to_vendor }}</li>
{% else %}
<li>{{ Vendor | link_to_vendor }}</li>{% endif %}
{% endif %}
{% endfor %}
</ul>

如果您想卖空卖方,请尝试以下代码
<ul class="filter">
{%Assign myvendor ='samsung,xaomi,Nokia'| split:,"%}
{%for myvendor中的供应商%}
{%,如果shop.vendors包含供应商%}
{%,如果collection.current_vendor ==供应商%} <li class="active"> {{供应商link_to_vendor}} </li>
{%else%}
<li> {{供应商| link_to_vendor}} </li> {%endif%}
{%endif%}
{%endfor%}
</ul>

if you want to short vendor try these code
<ul class="filter">
{% assign myvendor = 'samsung,xaomi,Nokia' | split:"," %}
{% for Vendor in myvendor %}
{% if shop.vendors contains Vendor %}
{% if collection.current_vendor == Vendor %} <li class="active"> {{ Vendor | link_to_vendor }}</li>
{% else %}
<li>{{ Vendor | link_to_vendor }}</li>{% endif %}
{% endif %}
{% endfor %}
</ul>

这篇关于如果选择当前供应商,如何捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 21:41