One of the most useful things that came along with sections is blocks. Blocks are basically a blueprint for something that can be created an unlimited amount of times. One of the best examples is the slides of a slider. A block is a top level item in the schema, meaning it is alongside things like name
and settings
, but not within them. Within blocks are basically mini schemas.
{% schema %}
{
"name": "Slider",
"max_blocks": 6,
"blocks": [
{
"type": "slide",
"name": "Slide",
"limit": 4,
"settings": [
{
"id": "image",
"type": "image_picker",
"label": "Image"
}
]
}
]
}
{% endschema %}
Notice the Slide also has a type of slide
. You can give your blocks their own type that is not one of the Shopify provided types.
To use this you would just loop over each block in your HTML/Liquid code.
<div class="slider">
{% for block in section.blocks %}
<img src="{{ block.settings.image | img_url: 'master' }}" alt="" />
{% endfor %}
</div>