Multiple Files Fields

Hi,

Sorry, very basic question which I’d love advice on - I’m trying to add multiple files fields to a page blueprint which are completely independent of each other, however when I upload an image in the first files field instance it is shown in the second files field instance.

In order to have multiple files fields within the same blueprint which are independent of each other, do I need to specify a file template for each files field?

Thank you,
Lewis

Yes, otherwise you cannot really separate them.

Thank you! I’ve just set that up and now the two fields are working in the panel and allowing ‘unique’ image uploads which is great. I’m not trying to output in the template using the example in the docs, but this isn’t working, any ideas?

<div class="container">
    <header class="intro">
        <?php if($image = $page->heroimage()->toFile()): ?>
            <img src="<?= $image->url() ?>" alt="">
        <?php endif ?>
    </header>
</div>

Are you sure you are using files fields? Not sections?

The code you posted above only works for files fields, where the selected files are stored in the content file.

Files fields are basically select fields, only optimized for files.

Ahhh, thanks for explaining - That makes sense as I have setup sections in the blueprint which in some cases I can remove as these are not needed.

In some cases, wouldn’t you want a files field within a section? I was under the impression you use sections as a way of grouping fields when looking at the below page, am I mistaken?:

title: Tech


icon: page


options:
  url: false
  status: false
  delete: false


columns:
  #Page Intro
  hero:
    width: 1/4
    sections:
      heroimage:
        type: files
        template: hero-image
        headline: Hero Image
        max: 1
        layout: cards
        image:
          cover: true
  intro:
    width: 3/4
    sections:
      headline:
        type: fields
        fields:
          headline:
            label: Headline
            type: textarea
            size: small
            buttons: false

Thank you,
Lewis

There are different types of sections: pages, files and fields => https://getkirby.com/docs/reference/panel/sections

Whether or not a files field or a files section is the better option depends on the use case, see also here:

And of course you can have a files field within a fields section.

That is so helpful, thanks so much for pointing out the differences - That all makes perfect sense now and not something I was 100% aware of when posting this.

Thank you!