How do I echo data from files

I have my files set-up to accept alt-text in picture’s, but how do I go about echoing that data?

<img src="<?= kirby()->urls()->content() . '/' . $site->logo(); ?>" alt="??" width="">

within the “logo();” I have a field called “alt” how do I call that field?

$site->logo(); is not a standard Kirby method. Have you written something custom?

Alt text is generally not stored within the image file itself, unless you have very specific EXIF data. In order to automatically pull alt text into a template, you will need to set up a .txt file containing metadata related to the image.

This is described in the Kirby documentation:


logo() is an image field type with a logo.jpg in it, logo.jpg has a logo.jpg.txt with a text field called alt which I want to echo

<?php if($logo = $site->logo()):  ?>
<img src="<?= kirby()->urls()->content() . '/' . $logo; ?>" alt="<?= html($logo->alt()) ?>" width="">
<?php endif ?>

this echo’s the logo url in the alt field

You have to check if $logo is an image:

<?php if($logo = $site->logo()->toFile()):  ?>
<img src="<?= $logo->url() ?>" alt="<?= $logo->alt() ?>" width="">
<?php endif ?>
1 Like

Thanks, Sonja. I missed the connection to defining an image field, since I rarely use blueprints.

Thanks guys for the quick help, it works!