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.

sets:
  image:
    display: Image
    fields:
      - handle: image
        field:
          mode: grid
          restrict: false
          allow_uploads: true
          display: Image
          type: assets
          icon: assets
          listable: hidden
          container: blog_images
          max_files: 1

In your Antlers template for the images just write

<div class="flex justify-center mb-2 max-w-4xl mx-auto">
  {{ image }} {{ glide:image tag="true" }} {{ /image }}
</div>

and you get your <img src="/path/to/my/container/" alt="My alternative text"> image tag rendered. Just easy to use. To add the alt attribute use alt="{ alt }" after the tag parameter.

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:

<div class="flex justify-center mb-2 max-w-4xl mx-auto">
  {{ image }} {{ responsive:image tag="true" }} {{ /image }}
</div>

This generates a tag with srcset to render images for differrent breakpoints.