# toStructure comes up null

**URL:** https://forum.getkirby.com/t/tostructure-comes-up-null/33662
**Category:** Questions
**Tags:** v4
**Created:** [February 22, 2025, 11:17pm UTC](https://forum.getkirby.com/t/tostructure-comes-up-null/33662 "2025-02-22T23:17:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![xVx](https://avatars.discourse-cdn.com/v4/letter/x/b2d939/32.png) [@xVx](https://forum.getkirby.com/u/xVx)
#### Post date: [February 22, 2025, 11:17pm UTC](https://forum.getkirby.com/t/tostructure-comes-up-null/33662/1 "2025-02-22T23:17:07Z")

</div>

Hi, this is my first question here.

I read through various forum posts, but none of the solutions have worked for me. My toStructure() code keeps coming up null.

This is the toStructure field in my blueprint:

```auto
  stories:
    label: Stories
    type: structure
    fields:
      story:
        label: Story
        type: text
      link:
        label: Link
        type: url

```

which produces this format:

```auto
Stories:
- 
  story: There once was a dog who drove a car.
  link: 'https://example1.com'
- 
  story: There once was a cat who flew a plane.
  link: 'https://example2.com'

```

I tried the code from [$field-\>toStructure()](https://getkirby.com/docs/reference/templates/field-methods/to-structure#example__template) and changed it like so:

```auto
<?php foreach (page('history')->children()->stories()->toStructure() as $story): ?>

   <a href="<?= $story->link() ?>">
      <?= $story->story() ?>
   </a>

<?php endforeach ?>

```

but it comes up null. I can get regular field data to show up in the template, but not the structured field data.

How to do render the data from the structure field in the template?

---

<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: [February 22, 2025, 11:23pm UTC](https://forum.getkirby.com/t/tostructure-comes-up-null/33662/2 "2025-02-22T23:23:56Z")

</div>

> [@xVx](#):
>
> `(page('history')->children()->stories()->toStructure() `

You cannot call a field (`stories()`) and a collection of pages, if you want to call the field, you first have to loop through the pages, then call `stories()->toStructure()` on the single page of the collection.

So

```auto
<?php foreach (page('history')->children() as $p): ?>

    <?php foreach ($p->stories()->toStructure() as $story): ?>
        <a href="<?= $story->link() ?>">
          <?= $story->story() ?>
       </a>

    <?php endforeach ?>
<?php endforeach ?>

```

---

<div class="post-metadata">

### Author: ![xVx](https://avatars.discourse-cdn.com/v4/letter/x/b2d939/32.png) [@xVx](https://forum.getkirby.com/u/xVx)
#### Post date: [February 22, 2025, 11:28pm UTC](https://forum.getkirby.com/t/tostructure-comes-up-null/33662/3 "2025-02-22T23:28:49Z")

</div>

That works! Thank you so much!!
