Thanks for the reply!
I try to show the images from the image block in it’s page template.
I don’t have a snippet for them so I loop through the blocks as you suggested. For some reason now the image src is undefined, any idea why? Maybe it’s because that the image block is a field that I’ve created and it’s not the default image/file block?
When I use filterBy(‘type’, ‘image’) - does it recognize this custom image block? or should I call it differently.
This is the variant for a single file. If you have more than one file in the image field, then you have to use toFiles() instead and then loop through the files.
For one file, I would limit the number of files that can be selected in the blueprint to 1.
I have another question - since I have another field: video, I would want it to show images and videos together. so I would want it to say that if it’s a video field show a video (vimeo). if it’s an image field show an image (as you suggested).
Any idea how should I write the php markdown?
Thank you!
You probably mean a video block, not a video field?
If I were you, I would create the snippet for your custom block and then just call
<?php echo $exhibit->media()->toBlocks(); ?>
This will then output all blocks in the order they appear in the blocks field and with the correct markup.
For me, your current markup doesn’t make sense if you want to output the blocks in the order they appear, i.e. if you first filter by image blocks, unless that is what you want?
Otherwise, loop through the blocks and output the manual code for the image block and the default snippet for the video block.
Ok I understand - so I need to create a snippet for my custom block.
I have created a snippet file called ‘image.php’ in the blocks folder inside the snippets folder.
How does the snippet should be? according to this I wrote the snippet like that:
<img src='<?= $block->url() ?>' alt=''>
and in the template I wrote this (as you suggested earlier):
in the inspect I can see it shows all the images but again giving me undefined src. any idea why?
and do I need to create a snippet for the video block too?
Thanks again! I’m new to Kirby - I really appreciate your help!
You are using the default video block, right? Then there is already a snippet for the video block and you don’t have to create it (unless you want to make changes to it).
My bad, I copied the wrong code into my code snippet above, sorry.
You might want to enhance this image snippet with a srcset attribute to make your image responsive, and if your image is not purely decorative but conveys meaning, don’t forget the alt text.
About the video, I used the default video block and it worked as well. but I would want to make some changes with the video so I thought I will make a custom field only for the link and then I will create a snippet for it too. I tried this one but it didn’t work: