Modifying image KirbyText tag to display caption from file metadata

In a new Kirby 3 site I am applying image metadata (captions, photographer, etc.) using file blueprints. I insert these images using the (image: ... ) kirbytext tag. I know you can manually add a caption with the caption: attribute when calling the tag. Would I would like to have is the kirbytext tag pull the caption from the image metadata if it exists while also maintaining the option of overwriting that caption if the caption: attribute is specified in the (image: ... ) kirbytext tag. It seems like I should just extend the image kirbytag ( but I am having a difficult time getting started. It seems like this would be a common problem, and I did find some solutions for Kirby 2, but none for Kirby 3. Hopefully this will help others as well.

It shouldn’t be necessary to create a custom tag. If you have a field called caption, it should be pulled automatically, while the metadata is overwritten if the caption property is used in the tag.

This is the line where this happens:

$tag->caption = $tag->caption ?? $tag->file->caption()->value();

Doesn’t that work? Does for me.

@texnixe, thank you so much for the prompt reply. Yes! You are absolutely right, the default image tag pulls in the caption, as well as the alt, metadata stored file blueprint. This seems to be new in K3? I seem to recall making my own custom image tag to achieve the same thing in K2. Apologies for the delayed response.