--- url: https://docs.youcan.shop/themes/blocks.md --- # Blocks Blocks are repeatable, individually configurable items inside a [section](/themes/sections/overview). Each section declares which block types it accepts; sellers then add, remove, reorder, and configure block from the theme editor. Common uses are slides in a slideshow, columns in a multi-column layout, items in a feature list, and products in a featured collection. ## Location Blocks aren't separate files. A block type is defined in the `blocks` array of a section's [`{% schema %}`](/themes/sections/section-schema#blocks), and rendered by that section's Liquid. Two sections can define unrelated block types that happen to share a name. ## Defining blocks Each entry in the section schema's `blocks` array describes one block type. ```liquid {% schema %} { "name": "Multi-column", "max_blocks": 6, "settings": [], "blocks": [ { "type": "column", "name": "Column", "limit": 6, "settings": [ { "type": "text", "id": "heading", "label": "Heading" }, { "type": "textarea", "id": "body", "label": "Text" } ] } ] } {% endschema %} ``` | Property | Type | Required | Description | | -------- | ---- | -------- | ----------- | | `type` | `string` | Yes | Identifier for the block type, referenced as `block.type` in Liquid. | | `name` | `string` | Yes | The block name shown in the theme editor. Can be a `t:` locale key. `label` is accepted as a deprecated alias. | | `limit` | `integer` | No | Maximum number of blocks of this type in the section. Defaults to `50`, and can't exceed `50`. | | `settings` | `array` | No | [Setting](/themes/settings/overview) definitions for the block, read through `block.settings`. | `max_blocks` on the section schema caps the total number of blocks across all types (default and maximum `25`). ## Rendering blocks Iterate `section.blocks` in the order the seller arranged them, and branch on `block.type`. ```liquid
{{ block.settings.body }}
{{ slide.settings.text }}
Add a column to get started.
{% else %} {% for block in section.blocks %} ... {% endfor %} {% endif %} ``` ## The `block` object | Property | Description | | -------- | ----------- | | `block.id` | Unique identifier for the block instance. Stable across edits; useful for scoping CSS or `id` attributes. | | `block.type` | The block's `type` as declared in the section schema. | | `block.settings` | The block's setting values, keyed by setting `id`. | | `block.youcan_attributes` | Theme-editor attributes to spread onto the block's root element. See [below](#integrate-blocks-with-the-theme-editor). | `section.blocks.size` gives the number of blocks. ## Where block data comes from * In a section added through a [JSON template](/themes/templates/json-templates), each block is an entry in that section's `blocks` object, and the section's `order` array sets the sequence. * In a [statically rendered](/themes/sections/overview#statically-render-a-section) section, blocks come from the matching section entry in [`config/settings_data.json`](/themes/config/settings_data). Either way, `section.blocks` in Liquid reflects the resulting list, already ordered. ## Integrate blocks with the theme editor For the theme editor to select, highlight, and live-update an individual block, output `block.youcan_attributes` on that block's outermost rendered element. ```liquid {% for block in section.blocks %} {% case block.type %} {% when 'heading' %}