# \-\>toPages() in multilevel structure

**URL:** <https://forum.getkirby.com/t/topages-in-multilevel-structure/13041>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 24, 2019, 8:39pm UTC](https://forum.getkirby.com/t/topages-in-multilevel-structure/13041 "2019-02-24T20:39:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [February 24, 2019, 8:39pm UTC](https://forum.getkirby.com/t/topages-in-multilevel-structure/13041/1 "2019-02-24T20:39:15Z")

</div>

How can I use the -\>toPages() method on a deeply nested mutlilevel structure field like this:

```
  header:
    label: Header
    type: structure
    max: 1
    fields:
      menu:
        label: Navigation
        type: structure
        max: 1
        fields:
          links:
            type: pages
            max: 6

```

The problem I am having the the following: When turning the header strucure to a array with this:  
`<php foreach($site->header()->yaml() as $header):?>`

Then I won’t be able to use toPages() like this:  
`<?php foreach($header['menu']->toPages() as $menu):?>`  
Since the Textfile is now transformed into an array.

Is there a way to reverse this and call -\>toPages() on a multilevel structure field?

---

<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 24, 2019, 8:41pm UTC](https://forum.getkirby.com/t/topages-in-multilevel-structure/13041/2 "2019-02-24T20:41:36Z")

</div>

I haven’t used nested structure yes, but I’d recommend using `toStructure()` instead of `yams()`.

---

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [February 24, 2019, 8:56pm UTC](https://forum.getkirby.com/t/topages-in-multilevel-structure/13041/3 "2019-02-24T20:56:20Z")

</div>

The same problen will persist. Since when you call toStructure in the end I will have an array of my “menu” field. And since -\>toPages() required the “default” yaml text format just like it is saved in the /content/site.txt and not a array/yaml or object to be given I cannot use -\>toPages or -\>toPage on this.

---

<div class="post-metadata">

**Author:** ![Ebbel](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@Ebbel](https://forum.getkirby.com/u/Ebbel)\
**Post date:** [February 24, 2019, 9:06pm UTC](https://forum.getkirby.com/t/topages-in-multilevel-structure/13041/4 "2019-02-24T21:06:42Z")

</div>

I would need some way so that in the end I still get:  
related:  
- fur-endkunden  
- fur-finanzdienstleister

Because only then I can call -\>toPages.

---

<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 24, 2019, 9:16pm UTC](https://forum.getkirby.com/t/topages-in-multilevel-structure/13041/5 "2019-02-24T21:16:32Z")

</div>

You have to loop through the structure like this:

```auto
<?php

$str = $site->header()->toStructure();
foreach($str as $item) {
  foreach($item->menu()->toStructure() as $menu) {
    dump($menu->links()->toPages());
  };
}
?>

```

---

<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 24, 2019, 9:45pm UTC](https://forum.getkirby.com/t/topages-in-multilevel-structure/13041/6 "2019-02-24T21:45:35Z")

</div>

@Ebbel Did you know we have a “Question 🤔 🤔 ” category for questions? Would be great if you could choose the question category that corresponds with your Kirby versions. Helps us to keep track and answer your question faster. Thanks.
