I want to make a section where I can add 3 images. Each image will be styled differently so must be wrapped in it’s own classes and elements.
I’ve been able to do the 3 images by using a for loop eg:
{% for block in section.blocks %}
<div class="image_box">
{{ block.settings.image | img_url: '150x150', scale: 2 | img_tag: block.settings.image.alt, 'logo-bar__image' }}
</div>
{% endfor %}
But, of course, this just means each image block is identical.
How can I display and style each image block uniquely?
My schema is as such:
{% schema %}
{
"name": {
"en": "Multi-hero"
},
"class": "index-section index-section--flush",
"max_blocks": 3,
"settings": [
],
"blocks": [
{
"type": "image",
"name": {
"en": "Image"
},
"settings": [
{
"type": "image_picker",
"id": "image",
"label": {
"en": "Image"
}
}
]
}
],
"presets": [
{
"name": {
"en": "Multi-hero"
},
"category": {
"en": "Image"
},
"blocks": [
{
"type": "image"
},
{
"type": "image"
},
{
"type": "image"
}
]
}
]
}
{% endschema %}
2
Answers
It kind of depends on how much control you want to give the user of the theme editing tools, but if you don’t mind exposing some more options to them you could try something like this:
And then use that in your output:
Or, if you want to change the image classes:
Instead of relying on For loop, you can use block type for different type of images. I used your code to create 3 different types of blocks, namely
Then used case to target different type of blocks.