Problem rendering image from file field... bug?

Hello!

in my site.yml I have put a files field that holds a logo png file that I want to output in the footer. The site.yml looks like this:

title: Site Template
sections:
  images:
    headline: Grafiken
    type: files
  content:
    type: fields
    fields:
      footerlogo:
        label: Footer Logo
        type: files
        multiple: false

  pages:
    type: pages

In my footer snippet I’m trying to render the image from this field in the following way:

<img src="<?= $site->image($site->footerlogo()) ?>" />

Which doesn’t give me any output. I also know why because when I dump($site->footerlogo()) I get the following:

Kirby\Cms\Field Object
(
    [footerlogo] => - >
  mcse-datamgmtanalytics-logo-blk-300x248.png
)

As you can see Kirby returns the filename with a - > prepended which leads to the case that $site->image() doesn’t get the correct filename and doesn’t give me a proper output.

I also tried different image files. Kirby sometimes prepends a - > and sometimes a -. This seems to be weird behaviour to me. I tried to allow multiple files in the file field which didn’t solve the problem.
How can I fix this? Is it a bug?

You have to use the toFile() method to fetch the file from the field content (it is stored in yaml format). Also, echoing the image instead of the URL is also not correct. And you should always use an if statement to check if the image exists.

<?php if ($img = $site->footerlogo()->toFile()): ?>
<img src="<?= $img->url() ?>" />
<?php endif ?>