2

在 Shopify 部分中,我有一个图像选择器块来制作画廊,在同一部分中,我有一个 url 块来制作任意数量的按钮。

问题是两种块类型都出现在主题编辑器的同一个“内容”区域中。这让编辑器看起来很混乱。

有没有办法拥有 2 个单独的块区域,一个用于图片库,另一个用于按钮?

在此处输入图像描述

"blocks": [
  {
    "type": "button",
    "name": "Button",
    "settings": [
      {
        "type": "url",
        "id": "button_link",
        "label": "Button link"
      }
    ]
  },
  {
    "type": "image",
    "name": "Image slide",
    "settings": [
      {
        "type": "image_picker",
        "id": "image",
        "label": "Image"
      }
    ]
  }
]
4

2 回答 2

5

不,目前没有办法告诉 Shopify 以这种方式显示块。无论每个块的“类型”是什么,所有块都可以按任何顺序排列。管理商店的人需要手动将块排列成合理的顺序。

如果你想在渲染项目的过程中更容易地分割你的块类型,你可以使用这样的东西:

{% assign image_blocks = section.blocks | where: 'type', 'image' %}
{% for block in image_blocks %}
  <!-- Stuff -->
{% endfor %}

{% assign button_blocks = section.blocks | where: 'type', 'button' %}
{% for block in button_blocks %}
  <!-- Stuff -->
{% endfor %}
于 2020-04-08T15:26:17.593 回答
1

创建 2 个不同的部分并包括两者。例如:

{% section 'buttons' %}

{% section 'images' %}

在哪里:

部分/按钮.liquid

{% schema %}
  {
    "name": "Buttons",
    "class": "buttons-section",
    "blocks": [
      {
        "type": "button",
        "name": "Button",
        "settings": [
          {
            "type": "URL",
            "id": "button_link",
            "label": "Button link"
          }
        ]
      }
    ]
  }
{% endschema %}

部分/图像.液体

{% schema %}
  {
    "name": "Images",
    "class": "images-section",
    "blocks": [
      {
        "type": "image",
        "name": "Image slide",
        "settings": [
          {
            "type": "image_picker",
            "id": "image",
            "label": "Image"
          }
        ]
      }
    ]
  }
{% endschema %}

所以你会得到这个:

包含两个部分的示例

于 2020-04-08T19:47:35.787 回答