Caption for image

What is the easiest way to display captions right under the images? I already put the following in the blueprint, but the text in the caption field is not displayed

files:
  fields:
    caption:
      label: Caption
      type: textarea

Thanks!

Did you add this caption-field in your template file?

I know how I can do this manually, but I thought there was an automatic way to do this to every image just by adding the caption field to the blueprint.

The tags.php looks like it should also return the caption for each image, or am I totally wrong here?

if(!empty($caption)) {
    $figure->append('<figcaption>' . html($caption) . '</figcaption>');
  }

If you add a caption field to your files in your blueprint, this generates a form for the file in the panel, where you can then add your caption. Of course, if you don’t add anything, nothing can be displayed. You might want to have a look at this post Adding metadata files for images within the panel.

Other than that, I don’t really understand what you mean by “automatically”…

[Edit] The tags.php adds a caption to your file if you add a Kirbytags to your fields like this:

(image: image.jpg caption: Some caption text)
1 Like

Ok, maybe my English is bad and I’m not properly expressing myself. I was trying to add captions to specific images in the post and was doing it the wrong way.

When searching for how to add captions, I only found solutions that involved blueprints. Instead the solution I just found was much simpler: Just add (image: lake.jpg caption: This is a lake) within the text. This displays the image and below the caption with a figcaption tag

This achieves everything that I was looking for. Sorry for causing trouble, but maybe this should also be mentioned somewhere more prominently (or I’m just very blind).

It’s in the section about formatting text http://getkirby.com/docs/content/text#images