Include multiple blocks in shopify section schema?

Wiivv_Wearables
Tourist
9 0 7

Is there a way to add multiple blocks sections to a Shopify schema?

Replies 3 (3)
Dejan_Strancar
Shopify Partner
6 0 8

Wiivv its possible yes by putting inside "blocks" array multiple block objects..

for example

{% schema %}
  {
    "name": "Multiple Blocks",
    "blocks":[
      {
        "type": "block-1",
        "name": "Block 1",
        "settings": [
          {
            "type": "text",
            "id": "title",
            "label": "Title"
          }
        ]
      },
      {
        "type": "block-2",
        "name": "Block 2",
        "settings": [
          {
            "type": "text",
            "id": "title",
            "label": "Title"
          }
        ]
      }
    ]
  }
{% endschema %}

{% for block in section.blocks %}
  {% if block.type == 'block-1' %}
    <h2>{{block.title}}</h2>
  {% elsif block.type == 'block-2' %}
    <h3>{{block.title}}</h3>
  {% endif %}
{% endfor %}

Hope that helps

MaxDesign
Shopify Expert
140 4 49

It helps tons.

 

If someone else find it uselful but can't make it work, you might have to replace

 

{{block.title}}

with

{{block.settings.title}}


Cheers.

Reach out to me at admin@maxdesign.expert
ji3
New Member
1 0 0

It helps a lot, Thanks for the solution.