shopify - Liquid 错误:数组“collection.products”不可分页
问题描述
我在section中创建了一个组件并写了名字bottom.liquid并从collection-template复制的代码都具有相同的架构并在section文件夹中创建但我只在bottom.liquid中出现错误
这是我的bottom.liquid代码
{% paginate collection.products by 12 %}
{% assign productCount = collection.all_products_count | minus: paginate.current_offset %}
<div class=" container-fluid lemon-con ">
<div class="column-title">
<h3 class="h3 main-lemo-heading text-center">
DIRTYLEMON
</h3>
</div>
<div class="row">
<div class="col-md">
{% if section.settings.collection_nav %}
{% assign sidebarNav = section.settings.collection_nav %}
<div class="list-card mb-4">
<div class="card-header product-hidden">
<strong>{{ linklists[sidebarNav].title }}</strong>
</div>
<ul class="list-group list-group-flush">
{% for link in linklists[sidebarNav].links %}
<li class="list-group-itm">
<a href="{{ link.url }}">{{ link.title }}</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if collection.all_tags.size > 0 and section.settings.hide_tags != true %}
<div class="list-card mb-4">
<div>
<strong>Tags</strong>
</div>
<ul class="list-group list-group-flush">
{% for tag in collection.all_tags %}
{% if current_tags contains tag %}
<li class="list-group-itm bg-primary">
{{ tag | link_to_remove_tag: tag }}
</li>
{% else %}
<li class="list-group-itm side-bar">
{{ tag | link_to_tag: tag }}
</li>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
{% endpaginate %}
{% schema %}
{
"name": "bottom",
"settings": [
{
"type": "header",
"content": "Collection header"
},
{
"type": "text",
"id": "title",
"label": "Heading",
"default": "slider title"
},
{
"type": "checkbox",
"id": "is_full_width",
"label": "Full width",
"default": false
},
{
"type": "select",
"id": "header_align",
"options": [
{
"value": "right",
"label": "Text right"
},
{
"value": "center",
"label": "Text center"
},
{
"value": "left",
"label": "Text left"
}
],
"label": "Header alignment",
"default": "left"
},
{
"type": "range",
"id": "header_height",
"min": 50,
"max": 500,
"step": 5,
"unit": "px",
"label": "Header height",
"default": 120
},
{
"type": "header",
"content": "Sidebar"
},
{
"type": "link_list",
"id": "collection_nav",
"label": "Navigation",
"info": "Select custom menu nav for sidebar"
},
{
"type": "checkbox",
"id": "hide_tags",
"label": "Hide tags",
"default": false,
"info": "Hide tags from sidebar"
},
{
"type": "header",
"content": "Others"
},
{
"type": "paragraph",
"content": "You can add more settings here :) "
}
],
"presets": [
{
"name": "bottom",
"category": "Image"
}
]
}
{% endschema %}
两者都有相同的代码,但我在bottom.liquid的bottom.liquid中遇到错误我在上面的图像collection.template上复制了相同的代码,但我只在bottom.liquid中遇到错误
解决方案
对于为什么它不起作用,Shopify Docs for Global objects没有提到 collection 作为全局对象。因此,您的代码仅适用于 Liquid 中的集合对象指的是正在查看的集合的集合页面。
所以你可以做的是,使用集合全局对象,然后使用集合句柄对所需的集合进行分页。
{% paginate collections['my-handle'].products by 12 %}
{% endpaginate %}
如果您想使用主题定制器选择 Collection,您可以使用Collection的设置类型。
{
"type": "collection",
"id": "feature_collection",
"label": "Feature collection"
}
推荐阅读
- arduino-esp8266 - 带有超声波传感器的 Blynk 通知
- linux - mmap 因 ENOMEM 失败
- php - 更改 mac os x 默认 php 版本
- excel - 将 Excel 工作簿合并到一个工作表
- angular - 如何在角度的外部extconfig.js文件中动态获取基于构建环境的环境变量
- android - 如何设置安装引荐来源网址,以便引荐来源网址库可以使用它
- c++ - 如何将char数组中的所有位设置为零?
- sql-server - 如何 DATETIME 正则表达式和拆分
- laravel - 我无法传递数据来查看它在 laravel 中显示 http 错误 500
- prometheus - 如何在 Prometheus 图表中以两条记录之间的间隔绘制数据点?