Formatting custom file fields

Hello,
I’m creating a website for a photographer and it’s important that he can add informations regarding his images (metadata, captions etc). To do so I added custom fields in the “article.yml” blueprint. How can I print this information when kirbytext is formatted in HTML?

files:
  fields:

    author:
      label: Autore
      default: Stefano Contilli
      type: text
      width: 1/2

    date:
      icon: calendar
      label: Data
      type: date
      format: LL
      default: today
      width: 1/2

    model:
      label: Modello
      type: text
      width: 1/2

    iso:
      label: ISO
      type: text
      width: 1/2

    shutterSpeed:
      label: VelocitĂ  Otturatore
      type: text
      width: 1/2

    aperture:
      label: Apertura
      type: text
      width: 1/2

    focalLength:
      label: Lunghezza Focale
      type: text
      width: 1/2

    caption:
      label: Descrizione
      type: textarea

File meta data fields are accessed via the file object.
Let’s suppose you want to loop through the file collection of a page and access your caption and author fields:

<?php foreach($page->images() as $image): ?>
<figure>
  <img src="<?= $image->url() ?>" alt="">
  <figcaption><?= $image->caption() .' | '.$image->author() ?></figcaption>
</figure>
<?php endforeach ?>

You can use Kirby’s field methods here as well, e.g. <?= $image->caption()->kirbytext() ?> if your field contains Markdown/Kirbytext formatted text.

Thank you for your answer!
But my idea was to print the info when the post’s text is formatted.
For example:
the user writes: (image: _mg_9266.jpg)
what appears is:

<figure>
...
<figure>
<p>
images metadata
<p>

So the informations are right after the image, is it possible?
Thanks

I see, this can be achieved with a custom image kirbytag, make a copy of the current imagetag, save it as a new tag and modify as required.

1 Like