Access image meta data in KirbyText tags?


I realize I can write:

(image: foo.jpg alt: foobar)

But I’m making use of the fantastic file blueprints feature to add an alt text field. Is it possible for me to access that data in a tag? Otherwise, it seems like having an alt text field is only useful in template code.

My use case is that I’m grabbing the first image of a page and using it in a list template as a cover image—so I need access to alt text in template code. But on the page itself, I need alt text in the main WSYSIWYG field. Currently, the only solution I can think of is to duplicate the alt text—once in the KirbyText tag and once in the image meta data.

Is there another way?


Guess what? You don’t have to do anything: Kirby picks up the content of an alt field defined in your meta data automatically unless you overwrite it in your tag.

$tag->alt     = $tag->alt     ?? $tag->file->alt()->or(' ')->value();

What other content of the meta data does kirby pick up automatically?


alt, title and caption:

$tag->alt     = $tag->alt     ?? $tag->file->alt()->or(' ')->value();
$tag->title   = $tag->title   ?? $tag->file->title()->value();
$tag->caption = $tag->caption ?? $tag->file->caption()->value();