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?
splorp
October 14, 2017, 10:55pm
2
$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:
https://getkirby.com/docs/content/media
2 Likes
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
texnixe
October 14, 2017, 11:07pm
4
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
splorp
October 14, 2017, 11:13pm
5
Thanks, Sonja. I missed the connection to defining an image field, since I rarely use blueprints.
Thanks guys for the quick help, it works!