How to get image Url from structured yaml field

I think it is a simple task but i get it wrong.

I try to get the image Url from a Structuredfield in a Snipper: My Code looks like this:

The Snippet looks like this (recommendations_new.php):

<?php foreach ($page->recomend_pages()->yaml() as $feat): ?>

       <img src="<?= $feat['picture'] ?>" />

            <?= $feat['name'] ?>
        <p class="description">
            <?= $feat['description'] ?>
        <a href="<?= $feat['link'] ?>" ><?= $feat['button'] ?></a>
<?php endforeach ?>

The Blueprint looks like this:

title: Home
    label: Inhalt
    icon: document
    preset: page
        label: Titel
        type:  text

        label: Titelbild
        type:  files

        label: Textinfo Header
        type:  textarea

        label: Teaser Links
        type: structure
        limit: 3
        entry: >
            label: Name
            type: text
            required: true
            label: Beschreibung
            type: textarea
            label: Bild
            type: files
            required: true
            label: Url
            type:  url
            required: true
            label: Button text
            type: text
          default: mehr erfahren »

The Template:

<?php snippet('header') ?>

    <section class="uk-section">
        <div class="uk-container">

            <div class="uk-width-1-1">
                $banner = $page->heading_banner()->toFile();
                if ($banner):?>
                    <img src="<?= $banner->url() ?>" alt="<?= $banner->name() ?>" style="width:100%;">
                <?php endif ?>

            <div class="tw-element uk-text-center tw-heading">
                <?= $page->heading_info()->kirbytext() ?>

            <?php snippet('blog') ?>
            <?php snippet('recommendations_new') ?>


    <div style="margin: 36px 0px 0px 0px; background: #004367; text-align: center; padding: 72px 48px;">
        <h3 style=" color:#fff; letter-spacing: 0.1em;">
            <?= $site->footer_info_text()->kirbytext() ?>

<?php snippet('footer') ?>

The Problem is with $feat[‘picture’] it gives me the word array in the frontend…

Any hints really appreciated.

What type do you use for the picture field and what is stored in it?

It is a files field and an image is stored in it, i want to retrive the image url and ideally the alt-tag text. The Code above is added.

Thank you in advance!

I prefer the toStructure() method for rendering content from a structure field to using yaml. You can fetch the image from the picture field using the toFile() method (I assume you only store a single image here (if so, you should probably set max: 1). If you store multiple images, use toFiles() instead and then loop through the collection.

Note that I’m using an if statement below to make sure I have an image object before rendering the image and calling the url() method.

<?php foreach ($page->recomend_pages()->toStructure() as $feat): ?>
  <?php if($img = $feat->picture()->toFile(): ?>
       <img src="<?= $img->url() ?>" />
  <?php endif ?>
       <h4><?= $feat->name()->html() ?></h4>
        <p class="description"><?= $feat->description()->html() ?></p>
        <a href="<?= $feat->link() ?>" ><?= $feat->button()->html() ?></a>
<?php endforeach ?>