突出显示shopify中的活动收藏按钮

突出显示shopify中的活动收藏按钮,shopify,Shopify,我在Shopify上有一个收藏清单。我试图使用link active标记,但它不起作用。这是我的片段 {% for collection in collections %} {% unless collection.handle == 'frontpage' %} <button type="button" class="btn btn-outline-info {% if link.active %}class='active'{% endif

我在Shopify上有一个收藏清单。我试图使用
link active
标记,但它不起作用。这是我的片段

{% for collection in collections %}
  {% unless collection.handle == 'frontpage' %}
    <button type="button" class="btn btn-outline-info {% if link.active %}class='active'{% endif %}">{{ collection.title | escape | link_to: collection.url }}</button>
  {% endunless %}
{% endfor %}
{%用于集合%中的集合}
{%除非集合.handle='frontpage%}
{{collection.title | escape | link_to:collection.url}
{%end除非%}
{%endfor%}
我正在尝试将
活动类
添加到活动集合或当前所在的集合URL


我不知道我在这里遗漏了什么。

根据您的评论,您的代码将无法正常运行
collection
是Shopify中的一个保留变量,通过在循环中使用相同的变量,您可能会完全更改实际的集合。其次,link.active只能在linklists循环中工作

您可以这样做:更改循环中单元的赋值变量,并验证句柄是否相同

{% for thisCollection in collections %}
  {% unless thisCollection.handle == 'frontpage' %}
    <button type="button" class="btn btn-outline-info {% if thisCollection.handle == collection.handle %}class='active'{% endif %}">{{ thisCollection.title | escape | link_to: thisCollection.url }}</button>
  {% endunless %}
{% endfor %}
{%用于集合%中的此集合}
{%除非thisCollection.handle=='frontpage%}
{{thiscolection.title | escape | link_to:thiscolection.url}
{%end除非%}
{%endfor%}

什么是
link.active
以及它从哪里来?@HymnZ我正在尝试将
active类
添加到活动集合中,或者添加到我当前所在的集合URL中。
link.active
仅在链接列表循环/对象中起作用。我在这里没有看到任何链接列表对象。如果link.active不起作用。有什么办法行得通吗?你在哪里添加代码?您可以使用collection.handle验证它吗。另外,不要在自定义循环中使用保留变量,如集合。