我正在为我的网站制作我自己的产品滑块。我有自己的动态部分,在‘定制主题’中,您可以选择5个产品。
我可以通过{{ section.setings.Product-1}来完成产品处理,但是如何获得产品id、产品名称、产品价格、产品形象url等等?
像{{ product.title }}这样的东西不起作用,因为它不知道从哪里提取信息。
我目前的代码是:
<div class="wrapper">
<div class="section-header text-center">
<h2 class="h1 section-header__title"> {{ section.settings.text-box }}
</h2>
</div>
<div class="rte">
<div class="gallery js-flickity" data-flickity-options='{ "freeScroll": true, "wrapAround": true }'>
<div class="gallery-cell"> </div>
<div class="gallery-cell"> Text </div>
<div class="gallery-cell"> Text </div>
<div class="gallery-cell"> Text </div>
</div>
</div>
</div>
{% schema %}
{
"name": "Featured Slider",
"settings": [
{
"id" : "text-box",
"type" : "text",
"label" : "Title of Section",
"default" : "Featured Products"
},
{
"type" : "product",
"id" : "product-1",
"label" : "Featured Product"
},
{
"type" : "product",
"id" : "product-2",
"label" : "Featured Product"
},
{
"type" : "product",
"id" : "product-3",
"label" : "Featured Product"
},
{
"type" : "product",
"id" : "product-4",
"label" : "Featured Product"
},
{
"type" : "product",
"id" : "product-5",
"label" : "Featured Product"
}],
"presets": [
{
"name" : "Featured Product Slider",
"category" : "Allsops Sections"
}
]
}
{% endschema %}因此,这个想法是在每个画廊-细胞div将是不同的产品。
发布于 2018-04-18 16:23:47
看起来你在使用一个很棒的部分,但是你并没有以一种有用的方式使用它。
各节为您的代码逻辑块(即动态内容)提供了一个非常好的补充。
{% schema %}
{
"name": "Featured Slider",
"settings": [
{
"id" : "text-box",
"type" : "text",
"label" : "Title of Section",
"default" : "Featured Products"
}
],
"blocks": [
{
"type": "slide",
"name": "Slide",
"settings": [
{
"id": "product",
"type": "product",
"label": "Featured Products"
}
]
}
],
"presets": [
{
"name" : "Featured Product Slider",
"category" : "Allsops Sections"
}
]
}
{% endschema %}
{% for block in section.blocks %}
{% assign product = all_products[block.settings.product] %}
<div class="slider">
<a href="{{ product.url }}">
<img src="{{ product.featured_image | img_url: 'master' }}">
{{ product.title }}
</a>
</div>
...
{% endfor %}通过这种方式,您可以添加尽可能多的幻灯片,并按您喜欢的方式重新排序。
至于您的问题,您可以使用all_products对象获取特定对象。在我提供的模式中,您可以看到我在这里使用它,{% assign product = all_products[block.settings.product] %}
请注意,all_products 只允许20个请求,除此之外,它还会抛出一个液体错误。
https://stackoverflow.com/questions/49903932
复制相似问题