Multiselected field in Blocks - Error: Array to string conversion

I am struggling to work with a multiselected field in Blocks that is querying data from the site.yml.

  1. I have a structure field on my site.yml .
  2. On my block I am querying elements of this structure via multiselect.

I think this thread almost suits my needs but it doesn’t work
https://forum.getkirby.com/t/structure-field-data-from-site-yml-output-on-page-via-multiselct-field/25636/2

However I get the message: “Block error: “Array to string conversion” in block type: "baslider”

Below is my Panel YML, Blocks YML and Blocks PHP

  1. Panel YML
fields:
  beforeafter:
    label: Before/After-Collection
    type: structure
    fields:
      ba_name: 
        label: Name
        type: text
        required: true

      ba_imagea:
        label: Before
        type: files
        query: site.find('myuploads').images
        uploads: 
          parent: site.find('myuploads')
        multiple: false

  1. Blocks YML

fields:
  baslider:
    label: BA-Slider
    type: multiselect
    min: 1
    options:
      type: query
      query: site.beforeafter.toStructure
      text: "{{ item.ba_name }}"
      value: "{{ item.ba_name }}"

  1. Blocks PHP

<?php if($block->isNotEmpty()): ?>

       <?php
       $items = $block->baslider()->split(',');

       foreach ($items as $item) {
         if ($sliderItem = $site->beforeafter()->toStructure()->findBy('ba_name', $item)) {
           echo $sliderItem->ba_imagea();
         }
       }
       ?>

<?php endif; ?>

Again, my error message is: “Block error: “Array to string conversion” in block type: "baslider”

Any ideas?

Thank you.

Could you do a dump($sliderItem->ba_imagea()) instead of echo and post the result? In any case, since you are using a files field, you should convert this field value to a file, see documentation of files field.

Hi texnixe,
thanks for the quick response. And yes, the result looks good. I think, I now know my mistake.
Here is the dump.

Kirby\Cms\Field Object
(
    [ba_imagea] => Array
        (
            [0] => file://Ub2TilE6kYpekn4N
        )

)

Yep, as I thought, in a block the field seems to behave a bit different, but after all, the values (even if just one), are stored in yaml, so the field value is an array.