# Access structure in template

**URL:** <https://forum.getkirby.com/t/access-structure-in-template/16198>\
**Category:** Questions\
**Tags:** v3\
**Created:** [November 6, 2019, 2:37pm UTC](https://forum.getkirby.com/t/access-structure-in-template/16198 "2019-11-06T14:37:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![janiblume](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@janiblume](https://forum.getkirby.com/u/janiblume)\
**Post date:** [November 6, 2019, 2:37pm UTC](https://forum.getkirby.com/t/access-structure-in-template/16198/1 "2019-11-06T14:37:02Z")

</div>

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

thats part of my yml-file:

```auto
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

```auto
<?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()

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 6, 2019, 2:43pm UTC](https://forum.getkirby.com/t/access-structure-in-template/16198/2 "2019-11-06T14:43:06Z")

</div>

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

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

```

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

> **[Structure](https://getkirby.com/docs/reference/panel/fields/structure#how-to-use-in-templates-snippets)**
>
> Structured data input, which stores data in a field as YAML.

---

<div class="post-metadata">

**Author:** ![janiblume](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@janiblume](https://forum.getkirby.com/u/janiblume)\
**Post date:** [November 6, 2019, 2:54pm UTC](https://forum.getkirby.com/t/access-structure-in-template/16198/3 "2019-11-06T14:54:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 6, 2019, 2:59pm UTC](https://forum.getkirby.com/t/access-structure-in-template/16198/4 "2019-11-06T14:59:47Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![janiblume](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@janiblume](https://forum.getkirby.com/u/janiblume)\
**Post date:** [November 6, 2019, 3:14pm UTC](https://forum.getkirby.com/t/access-structure-in-template/16198/5 "2019-11-06T15:14:59Z")

</div>

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