Issue with displaying images out of a structured content

Hi community

I have a question regarding the display of images that come from a structured content.
In kirby 2 I used to display images from structures as following:

    $toursections = $page->toursections()->yaml();
    foreach($toursections as $toursection):
      if($image = $page->image($toursection['image'])):
    <img src="<?= $image->url() ?>"> 

After migrating to kirby 3 and saving the files (with changed types of image to files), i get the following error:
Argument 1 passed to Kirby\Cms\Page::image() must be of the type string or null, array given, called in /Users/hopper/dev/product-landing-pages-kirby3/site/shared/snippets/iconlistrow.php on line 4

I assume that this is happening, because files returns an array instead of just a string as image did in kirby 2.
Now I kind of worked my way around this with:

if($image = $page->image(A::first($toursection['image']))):

Is there a better or even a proper way, how to get the images out of the structured content?

Thanks in advance for any advice!

Yes, use toStructure() instead of yaml() to work with your structure field

$toursections = $page->toursections()->toStructure();
foreach($toursections as $toursection):
     if($image = $toursection->image()->toFile()):

Thank you texnixe for your always blazing fast reply, really appreciate this!

I changed this according to your proposal. Now I got the following error though:

Cannot use object of type Kirby\Cms\StructureObject as array

Do I only get a single object or is it still an array? because with files it could also be multiple images in the field, right?

Are you still trying to fetch some other data from that field using array syntax maybe?

yep that was it… :slight_smile: thanks a lot for your help!