Including blocks inside a block

batulkr
Excursionist
25 1 0

Hey everyone!

I have been trying to include some blocks inside a block( I am not really sure if it is possible or not though) but could not manage to do that. If it is possible to do, what am I doing wrong here?

Here is my code:

{% schema %}
  
  {
  	"name": "FAQ Heading",
  	"settings": [{
  			"type": "header",
  			"content": "Heading and Description"
  		},
  		{
  			"type": "text",
  			"label": "Title",
  			"id": "heading"
  		}
  	],
  	"blocks": [{
  		"type": "block-1",
  		"name": "Block 1",
  		"settings": [{
  				"type": "text",
  				"label": "Your Text Here ",
  				"id": "text"
  			},
  			{
  				"type": "url",
  				"label": "Your Link Here",
  				"id": "call-to-action"

  			}
  		],
  		"blocks": [{
  			"type": "block - 1 - 1 ",
  			"name": "Block alt",
  			"settings": [{
  				"type": "text",
  				"label": "youretx here",
  				"id": "text-f"
  			}]
  		}]
  	}]
  }
{% endschema %}
0 Likes
Mircea_Piturca
Shopify Partner
1459 39 284

You can not nest blocks but you can have more block types:

"blocks": [
  {
    "type": "block-1",
     "name": "Block 1",
     "settings": [...]
  },
  {
    "type": "block-2",
     "name": "Block 2",
     "settings": [...]
  }
]
Finally—Add variant descriptions to your products
0 Likes
batulkr
Excursionist
25 1 0

Hello @Mircea_Piturca, thanks for the answer. But this is not what I am looking for. I already know this. What I mean is that, let's say, including blocks inside a nestetd block. For example, there is block-1, right? I would like to include some other blocks inside that nested block "block-1". Is that possible? 

0 Likes
Mircea_Piturca
Shopify Partner
1459 39 284

No, block nesting is not possible.

Finally—Add variant descriptions to your products
unofficial2321
Excursionist
16 0 3

@Mircea_Piturca  how can i call the type-2 block?

0 Likes
Mircea_Piturca
Shopify Partner
1459 39 284

You can do a loop with a conditional:

{% for block in section.blocks %}
  {% if block.type == 'type-1' %}
    ...
  {% elsif  block.type == 'type-2'  %}
    ...
  {% endif %}
{% endfor %}

 

You can also do some cool things with map. Depends what you are looking for.

Finally—Add variant descriptions to your products
0 Likes
unofficial2321
Excursionist
16 0 3

you have used condition but i want to access both somthing like this

<section>
  <div>
    {% for block in section.blocks.image-1 %}
    <div>{{ block.image-1.settings.text }}</div>
    {% for block in section.blocks.image-2 %}
    <div>{{ block.image-2.settings.text }}</div>
    {%endfor%}
    {%endfor%}
  </div>
</section>
0 Likes