Blocks
Blocks are Liquid files that allow you to create reusable modules of content that can be customized in the Basker Studio.
For example, you can create an Image with an Upload field that displays an image and text side-by-side with options for editors to choose the image, set the text, and select the display order.
Blocks can also be included statically, which can provide editors with in-context customization options for static content.
By default, blocks are available for any template. You can limit which templates have access in the block schema.
Location
Layout files are located in the layouts
directory of the theme:
Block Schema
Blocks support the {% schema %}
Liquid tag. This tag allows you to define various attributes of a blokc, such as the block name, and settings to allow for customization in the Basker Studio.
Schema
Each section can have only a single {% schema %}
tag, which must contain only valid JSON using the attributes listed in Content below. The tag should be placed at the bottom of the block file.
The following is an example of a valid block schema:
Content
The content of {% schema %}
can include the following attributes:
name
(required): A unique name that will be used to reference this block from the template. This name must match the name of a block in the theme’sblocks
directory.singular
: The singular version of the name, which is displayed when there are multiple instances of the block on a page.plural
: The plural version of the name, which is displayed when there is only one instance of the block on a page.label
: A human readable label for the block that will be used in Basker Studio.settings
(optional): An array of settings to customize this block’s appearance and behavior.
name
The name
attribute is required and must be a unique name that will be used to reference this block from the template. This name must match the name of a block in the theme’s blocks
directory.
singular
The singular
attribute is optional, but if provided it must be a string that will be used as the singular version of the name when there are multiple instances of this block on a page. If not provided, the value of name
will be used for the singular version.
plural
The plural
attribute is optional, but if provided it must be a string that will be used as the plural version of the name when there are multiple instances of this block on a page. If not provided, the value of name
will be used for the plural version.
label
The label
attribute is optional, but if provided it must be a string that will be used as the label for this block when displayed in Basker Studio. If not provided, the value of name
will be used for the label.
settings
You can create block specific settings to allow editors to customize the block with the settings object:
Rendering Blocks
In your template’s Liquid file, you can loop over the blocks of the page and render each block based on its type. You can access the settings of the block using the block Liquid tag. The following is an example: