Access structure in template

i’m new to Kirby and can’t figure out how to acess my structure in the frontend.

thats part of my yml-file:

title: Home

sections:
  home:
    type: fields
    fields:
      news:
        label: News
        type: structure
        min: 3
        max: 3
        sortBy: date
        fields:
          date:
            label: Datum
            type: date
          headline:
            label: Überschrift
            type: text
          text:
            label: Text
            type: textarea
          image:
            label: Bild
            type: files
            max: 1
            min: 1

ans thats my php

<?php
      // using the `toStructure()` method, we create a structure collection
      $news = $page->news()->yaml();
      var_dump($news);
      // we can then loop through the entries and render the individual fields
      foreach ($news as $new): ?>
        <a class="news-date"><?= $new->date() ?></a>
        <a class="news-title"><?= $new->headline()?></a>
        <a class="news-description"><?= $new->text()?></a>
      <?php endforeach ?>

As far as I can see its similar to the one in the docs. I really can’t find my mistake.
The var_dump shows array(0) { } for yaml() and object(Kirby\Cms\Structure)#284 (0) { } for toStructure()

If you want to use arrow syntax, you have to use the toStructure() method, not yaml() to turn your field into a structure object:

$news = $page->news()->toStructure();

Then do your loop. With yaml() you get an array and would have to use array syntax: $new['date'] etc.

Thank you!

But when I try to use

 $news = $page->news()->yaml();
 ...
 <a class="news-date"><?= $new['date'] ?></a>

I get an ecception error Undefined index: date

When I try

 $news = $page->news()->toStructure();
  var_dump($news);

I get object(Kirby\Cms\Structure)#284 (0) { }
But I added some news-entries in the panel

So I guess my main problem is, that my array or structure object is empty, although there are entries in the yml-file and inside the panel.

Using the structure is much more comfortable then using yaml, so I’d go with that.

Hm, have you saved the page? Are you in the correct template? $page always refers to the current page…

Thank you so much and I’m sorry for bothering.
Apparently I didn’t save the changes inside the panel.