Adding metadata files for images within the panel

This may have been posted within the old forum. In the Languages section of the Kirby Docs, I noticed that there was a section discussing the translation of file meta information. In it there was example with a file, myimage.jpg, having accompanying meta files such as myimage.jpg.en.txt ect.

The meta information I want to add to these txt files are not something you could find using $exif as they are custom graphics I’m exporting out of Illustrator. I would like to add to these meta files, such as myimage.jpg.en.txt, info such as author, copyright, liciencing, caption ect.

Can these meta files be produced within the panel or do I have to add them manually to its respective folder in /content? If this can’t be done, is there a plugin fo this. If not, is this something that would be worthy of a plugin?

Cheers,
Paul B.

The metadata files can be created via the panel. All you need to do is define the fields you need in the blueprint, for example:

<?php if(!defined('KIRBY')) exit ?>
title: Project Page
pages: true
files: true
  fields:
    author:
      label: Author
      type: text
    copyright:
      label: Copyright
      type: text
    caption:
      label: Caption
      type: textarea
fields:
  title:
    label: Titel
    type:  text

Then once you have uploaded a file and click on it in the sidebar of the panel, the “image editor” is opened and you can add the information for each file.

7 Likes

@texnixe Sorry for the late reply. This was a huge help to me. Many thanks

-Paul

Hey,

This was also a huge help for me. Thank you ! I have the Image Meta Information addedin the CMS Panel.
But, how I can enquiries the Image Meta Information with <php echo ... ?>

Sorry for my bad englisch !

// Deutsch

Danke für die Hilfe ! Die Meta Informationen für jedes einzelne Bild habe ich bereits im Panel hinzugefügt. Wie kann ich nun diese mit php echo abfragen ? ich möchte das mit einer schleife machen.

<

?php foreach($page->files()->not('2.png') as $file): ?>
  <figure><img src="<?php echo $file->url() ?>" width="100%" /><figcaption> !!!!!!!!! METAINFORMATIONEN !!!!!!</figcaption> </figure>
    <?php endforeach ?>

This is pretty straightforward, if your meta info field is called “caption”, you can call it like this:

<figcaption><?php echo $file->caption() ?></figcaption>

Just replace with your metadata field names … Then add ->html() or ->kirbytext() methods depending on the type of field …

BTW. If your folder contains other files that images, you may want to limit your call to images, i.e. instead of using $page->files() use $page->images()

@texnixe This is useful. Is this snippet found in the docs?

You can find examples in the content section: https://getkirby.com/docs/content/media

Hello,

I’am do not understand how add the caption field at the ‘Image Editor’

This is my blueprint:

<?php if(!defined('KIRBY')) exit ?>

title: Default
pages: Pages
files: true
fields:
  title:
    label: Title
    type: title
  richtext:
    label: Text
    type:  markdown
    size: big
  tags:
    label: Tags
    type: tags
  images_post:
        label: Image
        type:  selector
        mode:  multiple
        types:
            - all
  caption:
    label: Image-Caption
    type: text
  formular:
    label: formular
    type: checkbox
    text: Display Form?
  dayNight:
    label: dayNight
    type: checkbox
    text: Display Button Day-Night?
  notInMenu:
    label: notInMenu
    type: checkbox
    text: Not in menu

Greetings Perry

You can find the details here: https://getkirby.com/docs/panel/blueprints/file-settings

Basically, you define the fields for the metadata in the hierachy under the file settings.

Thank you texnixe.
Now I understand

quick question (I don’t want to start a new thread):

Can I do this globally? So have an alt tag for all images there are; or do I have to add the caption to all blueprints?

Thanks!

You can add an alt field to each file so you can define one for each image.

To define an alt tag for all images on the site you can also use an additional text field for example in the site.yml or any other blueprint.

Another way to define a fallback is using the ->or() function in the template. That can look like this:

<?= $image->html($image->alt()->or($site->alt())) ?>

Or without defining an additional field using the site name, as I sometimes do:

<?= $image->html($image->alt()->or($site->title())) ?>

Yes, the fields have to be added to each individual blueprint. You can use global field definitions, so that there’s less code in each file.

@thguenther I my opinion it doesn’t make sense to add the same alt attribute to all images, since it doesn’t add any additional value, it would be better to leave the value empty, if not meta data exists?

@texnixe I think I didn’t understand the question correctly. I thought about using an alt tag for all images, not all blueprints.

But if I remember correctly, an alt tag should not be empty. Not sure how this affects the ranking or anything, but I sometimes provide the website or page title as the fallback. That might not be ideal, though.

Heya

@thguenther no this is not the problem :wink:

I want to add an alt tag to all images, as explained above, but instead of changing every blueprint to add the alt tag, I wanted to know whether or not I can define one globally

@texnixe mhh I thought so - thanks! :slight_smile:

No, from what I have read regarding accessibility and screen readers etc. it doesn’t make sense to add a value to an image if it is purely decorational for example, or if the value doesn’t add any value. In such cases, it is better to leave the alt attribute empty (not remove it completely, though).