Theme block targeting
Theme block targeting allows theme developers to specify which blocks can be used in a section. In a theme section, theme developers can choose to:
- Accept all theme blocks for use
- Accept specific theme blocks for use
Anchor to Accept all theme blocksAccept all theme blocks
To accept all theme blocks in a section by adding a generic entry of type @theme
to the blocks attribute of the schema of that section. To be more restrictive about which blocks can be use in specific sections, use block targeting.
In the following example, the Section will have access to all theme blocks.
/sections/section.liquid
Anchor to Accept specific theme blocksAccept specific theme blocks
To accept specific theme blocks, theme developers can explicitly reference blocks in their schema. In the following example, the Slideshow section will have access to only the Slide theme block. In the editor, the block picker for Slideshow will only have a single block: slide. By default, theme blocks are available in all sections and theme blocks. In this example, the slide block will be in the block picker for all sections, not just the slideshow section.
/blocks/slide.liquid
/sections/slideshow.liquid
Anchor to Private blocksPrivate blocks
There are cases where you might want to limit the blocks that are available in sections. For example, slides are a type of block that should only be available in slideshow sections. To prevent the default behavior, theme developers can name the block with an underscore prefix.
In this case, slide.liquid
can be renamed to _slide.liquid
. All underscore prefixed blocks would be excluded from appearing in the block picker for blocks and sections that accept blocks with type @theme
. Those blocks and sections will need to explicitly add the block by base filename. Ex: "blocks": [ { "type": "_slide" } ]