How to access fields on page object in a correct manner?

Hello :slight_smile:

I have a pretty simple structure:
A page object that has a files field holding images of team members:

title: Team
icon: 👥

sections:
  content:
    type: fields
    fields:
      teammembers:
        label: Team Mietglieder
        type: files
        uploads: teammember
        layout: cards
        info: "{{ file.fullname }}"

I am utilizing file blueprints to store name and description of the team members in the corresponding files:

title:
  en: Teammember
  de: Team Mietglied

accept: image/*

fields:
  fullname:
    label: name
    type: text
  description:
    type: text

All well and good so far but now I want to access said images and their data on a page to render them:

<?php foreach (page('Team')->teammembers()->first()->toArray() as $member) : ?>
                <div class="col-lg-4 col-md-6 col-sm-12 text-center teamcard">
                    <div class="teamcard-bg">
                        <img class="mb-3" src="<?= $member->url() ?>" alt="">
                        <h4 class="mb-2"><?= $member->fullname() ?></h4>
                        <span><?= $member->description() ?></span>
                    </div>
                </div>
            <?php endforeach; ?>

as far as i understand the code goes like this:
teammembers() returns an array of all fields that are named “teammembers”
thats why I am calling first() on it to just receive the only element that exists.
Now first() has returned me a php object of type “field”.
Since the field I have specified in the blueprint is of type “files” and holds multiple images I assume I need to call the toArray() function.

But this only returns me strings of the files:
“- file://r1CfpSVeeG59zv25 - file://kxnLWmihYqR9iHS8 - file://q7bmfN6iBFRMqYB4 - file://ws8yIkz26ZHg9diq - file://bdpPGgkdDG3k9e3Y - file://ozjwD29Gegn59h38”
it even has the dashes and file:// just like it is stored in the content file.

I havent found a way to convert these strings into the actual images and I feel like this is probably the wrong approach I am taking here.

If I instead do page(‘Team’)->teammembers()->images() and iterate over these it works without a problem but it doesnt sort the images in the way I manually dragged them in the “team” page panel.
And calling “images()” only seems like a band-aid fix since if I were to retrieve any other field or data Id face the same issues as above again.

What am I misunderstanding?
I appreciate any and all help :slight_smile:

No, teammembers is a field and therefore returns a field object, you can never have multiple fields with the same name in the same blueprint.

Since teammembers is a files field, you need to convert the field content, see using files field in template: Files | Kirby CMS

Thank you for the quick reply!
While true that calling first is not necessary it didnt make a difference, the resulting object is the same regardless of calling first on it or not.

The actual difference I had to make is call toFiles() on it which converted it from a “field” object to a “files” object.

This was the misunderstanding that I had, needing to convert it. I didnt even know the function toFiles() existed since it isnt shown in the docs for the field object class.

Correct code:

<?php foreach (page('Team')->teammembers()->toFiles() as $member) : ?>
                <div class="col-lg-4 col-md-6 col-sm-12 text-center teamcard">
                    <div class="teamcard-bg">
                        <img class="mb-3" src="<?= $member->url() ?>" alt="">
                        <h4 class="mb-2"><?= $member->fullname() ?></h4>
                        <span><?= $member->description() ?></span>
                    </div>
                </div>
<?php endforeach; ?>

thanks for the help :slight_smile:

They have their own place in the documentation, because their purpose is to modify the field value etc. Field methods | Kirby CMS