销毁类似于wp_reset_query()的液体循环
Destroy liquid loop similar to wp_reset_query()
我有一个包含 collection 列表的菜单 (linklists.all-collections
)。菜单输出 collection 标题,url 以及使用 collection.all_tags
.
与 collection 关联的任何标签
菜单输出正常,但是下次我在 collection 模板页面上调用 collection.title
时,它会输出菜单中的最后一个 collection 标题,而不是 collection 当前 collection 页面的标题。
有没有办法关闭循环(类似于 WordPress wp_reset_query()
销毁之前的查询并设置新查询的方式)?
菜单是:
<ul>
{% for link in linklists.all-collections.links %}
{% assign collection = link.object %}
<li class="sidebar-menu-item {{ collection.handle }}">
<a href="{{ collection.url }}" title="{{ 'collections.general.link_title' | t: title: collection_title }}">{{ collection.title }}</a>
<ul>
{% for tag in collection.all_tags %}
{% unless tag == 'exclude' %}
<li>
<a href="{{ shop.url }}/collections/{{ collection.handle }}/{{ tag }}">{{ tag }}</a>
</li>
{% endunless %}
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
问题是由这一行引起的:
{% assign collection = link.object %}
顺便说一下,您不需要这样做来访问您的 collection 属性:
https://help.shopify.com/themes/liquid/objects/link#link-object
这样的东西应该可以工作(未测试):
<ul>
{% for link in linklists.all-collections.links %}
<!-- First check if your link is collection -->
{% if link.type == 'collection_link' %}
<li class="sidebar-menu-item {{ link.object.handle }}">
<a href="{{ link.url }}" title="{{ 'collections.general.link_title' | t: title: collection_title }}">{{ link.object.title }}</a>
<ul>
{% for tag in link.object.all_tags %}
{% unless tag == 'exclude' %}
<li>
<a href="{{ shop.url }}/collections/{{ link.object.handle }}/{{ tag | handleize }}">{{ tag }}</a>
</li>
{% else %}
<!-- If condition not met continue to next iteration -->
{% continue %}
{% endunless %}
{% endfor %}
</ul>
</li>
{% else %}
<!-- If not collection link, continue to next iteration in the loop -->
{% continue %}
{% endif %}
{% endfor %}
</ul>
我有一个包含 collection 列表的菜单 (linklists.all-collections
)。菜单输出 collection 标题,url 以及使用 collection.all_tags
.
菜单输出正常,但是下次我在 collection 模板页面上调用 collection.title
时,它会输出菜单中的最后一个 collection 标题,而不是 collection 当前 collection 页面的标题。
有没有办法关闭循环(类似于 WordPress wp_reset_query()
销毁之前的查询并设置新查询的方式)?
菜单是:
<ul>
{% for link in linklists.all-collections.links %}
{% assign collection = link.object %}
<li class="sidebar-menu-item {{ collection.handle }}">
<a href="{{ collection.url }}" title="{{ 'collections.general.link_title' | t: title: collection_title }}">{{ collection.title }}</a>
<ul>
{% for tag in collection.all_tags %}
{% unless tag == 'exclude' %}
<li>
<a href="{{ shop.url }}/collections/{{ collection.handle }}/{{ tag }}">{{ tag }}</a>
</li>
{% endunless %}
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
问题是由这一行引起的:
{% assign collection = link.object %}
顺便说一下,您不需要这样做来访问您的 collection 属性: https://help.shopify.com/themes/liquid/objects/link#link-object
这样的东西应该可以工作(未测试):
<ul>
{% for link in linklists.all-collections.links %}
<!-- First check if your link is collection -->
{% if link.type == 'collection_link' %}
<li class="sidebar-menu-item {{ link.object.handle }}">
<a href="{{ link.url }}" title="{{ 'collections.general.link_title' | t: title: collection_title }}">{{ link.object.title }}</a>
<ul>
{% for tag in link.object.all_tags %}
{% unless tag == 'exclude' %}
<li>
<a href="{{ shop.url }}/collections/{{ link.object.handle }}/{{ tag | handleize }}">{{ tag }}</a>
</li>
{% else %}
<!-- If condition not met continue to next iteration -->
{% continue %}
{% endunless %}
{% endfor %}
</ul>
</li>
{% else %}
<!-- If not collection link, continue to next iteration in the loop -->
{% continue %}
{% endif %}
{% endfor %}
</ul>