Render images in Statamics Bard
The Bard fieldtype is a beautiful idea to create long texts containing images, code samples - basically any sort of content. While I was creating my blog I was not sure how to extract images from the Bard field.
Thanks to the Glide tag you can just simply pass the field of your image and it automatically outputs the proper url. My image field is a set called image.
1sets:
2 image:
3 display: Image
4 fields:
5 - handle: image
6 field:
7 mode: grid
8 restrict: false
9 allow_uploads: true
10 display: Image
11 type: assets
12 icon: assets
13 listable: hidden
14 container: blog_images
15 max_files: 1In your Antlers template for the images just write
1<div class="flex justify-center mb-2 max-w-4xl mx-auto">
2 {{ image }} {{ glide:image tag="true" }} {{ /image }}
3</div>Responsive images
For generating responsive images you can use the excellent Statamic Responsive Images addon provided by Spatie. With this the above snippet changes to that:
1<div class="flex justify-center mb-2 max-w-4xl mx-auto">
2 {{ image }} {{ responsive:image tag="true" }} {{ /image }}
3</div>This generates a tag with srcset to render images for differrent breakpoints.