How to traverse theme block

How to traverse theme block.
the code in Below, is not Works.

{% for block in content_for ‘blocks’ %}

{{ block }}

{% endfor %}

Hi, that is not valid liquid. You should just be using the following below, you do not need to loop over the blocks.

{% content_for 'blocks' %}

i want to use theme blocks in swiper,so i need use for… in … to render it
just like

{% for block in content_for ‘blocks’ %}


{{ block }}

{% endfor %}

You should probably look into a combination of dynamic + static blocks.
You can read more here: Static Blocks

it’s not this, and i use render solve it , thanks.
And i have another quesion,
how can i control a theme block can not choose itself?

Define the exact block types you want to enable in that block.
i.e.

"blocks": [{ "type": "yourcustomblock" }]

instead of

"blocks": [{ "type": "@theme" }]

As others have mentioned above, you can render theme blocks using the {% content_for "blocks" %} tag.

We strongly encourage you use {% content_for "blocks" %} to render theme blocks.

Alternatively, if you have an advanced use case, you can iterate over theme blocks using a for loop. Since the markup for theme blocks lives in a different file, you have to delegate rendering by passing the block drop to the render tag:

Example 1: Manually rendering theme blocks from a section:

{% for block in section.blocks %}
  {% render block %}
{% endfor %}

Example 2: Manually rendering theme blocks from another theme block, in reverse order:

{% assign reversed_blocks = block.blocks | reverse %}

{% for block in reversed_blocks %}
  {% render block %}
{% endfor %}
1 Like