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 %}">{{ collection.title | escape | link_to: collection.url }}</button>
{% endunless %}
{% endfor %}
我正在尝试添加active class
到活动集合或我目前所在的集合 URL。
我不知道我在这里错过了什么。
解决方案
根据您的评论,您的代码将无法正常运行。collection
是 Shopify 中的保留变量,通过在循环中使用相同的变量,您可能会完全更改实际集合。其次,link.active 只能在链接列表循环中工作。
您可以执行以下操作:更改循环中单元的分配变量并验证句柄是否相同。
{% 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 %}
推荐阅读
- c# - 创建新的 .NetCore MSTest 项目并得到一个错误,指出命名空间“Microsoft”中不存在“VisualStudio”
- c++ - 使用队列和堆栈c ++的后缀评估
- node.js - 优化MongoDB中的聚合
- java - 如何表示一个长于 long 的数字并打印出来
- java - 范围内的代理模式
- c - free pointer by other pointer points same memory
- c# - Direct2D,WPF D3D10 图像在调整大小时模糊
- node.js - 在 Dockerfille 上运行 Angular 通用应用程序
- javascript - 如何在 img src 中指定图像本地路径以在 react/JavaScript 中加载
- c++ - CGAL构造球面多面体