A block represents the content and settings of a single block in a list of section blocks. In a section file you access the block object by looping over section.blocks.
{% for block in section.blocks %}
<!-- output block content -->
{% endfor %}
The block object has the following attributes:
block.id
Returns a unique ID generated dynamically by VersaCommerce.
block.settings
Returns an object with the block settings set in the theme editor. Access setting values by the unique setting id.
<img src="{{ block.settings.image | image_url: width: 800 }}" alt="{{ block.settings.image.alt }}">
<img src="//cdn.versacommerce.de/.../promo-banner1.jpg&width=800" alt="New season - Spring 2017">
block.shopify_attributes
Returns a string with the attributes of the block.
The theme editor's JavaScript API uses a block's shopify_attributes to identify blocks and listen for events. In the theme editor, VersaCommerce outputs the data-shopify-editor-block attribute here (with the block's id and type as JSON). Outside the theme editor, block.shopify_attributes is an empty string.
block.type
Returns the type defined in the block's schema. This is useful to show different markup depending on block.type.
{% for block in section.blocks %}
{% if block.type == 'advert' %}
<!-- output an image with a link -->
{% elsif block.type == 'headline' %}
<!-- output a header with text -->
{% endif %}
{% endfor %}
More properties
VersaCommerce also provides these properties on the block object:
| Properties | Returns |
|---|---|
blocks, static? |
Nested active children and static-block status |