Alt text for images in /assets/images/

I want to (re)use an image (‘partner-logos.png’ which lives in ‘/assets/images/’) with an alt text. But when I use a txt file (‘partner-logos.png.en-US.txt’) and use <?= $image->alt(); ?> in my template it gives an error (“The method: “alt” does not exist”). How would I go around this without adding the alt text itself in the template?

Metadata files only work for files in the content folder, not for files in /assets etc.

It might make sense to move this file to the content folder instead.

A bit inconvenient, because it needs to be the same in different places. Or maybe I could add a translation. It is strange images in assets are ‘not allowed’ to have an alt text.

If you add it to the site instead of a page, it shouldn’t be a problem?

A bit inconvenient, because it needs to be the same in different places.

In that case you can store it at the top content level so where site.txt lives. You can then access the image directly doing $site->image('partner-logos.png') or in one of the other available methods.

It is strange images in assets are ‘not allowed’ to have an alt text.

It is not strange because assets is outside of the scope of the content and the kirby panel only deals with content stored inside the content folder.

1 Like