# How to virtual pages in pages-section

**URL:** <https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613>\
**Category:** Questions\
**Tags:** v3\
**Created:** [October 2, 2020, 3:42pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613 "2020-10-02T15:42:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![andio](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andio/32/9117_2.png) [@andio](https://forum.getkirby.com/u/andio)\
**Post date:** [October 2, 2020, 3:42pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/1 "2020-10-02T15:42:53Z")

</div>

I’ve got a pages section, where the pages are queried from `page.lists`

In the model i defined:

```auto
<?php
class NewsletterlistsPage extends Page {
  public function lists($options = null) {

    // this contains three real children pages
    $lists = $this->childrenAndDrafts();

    // now i want to add a virtual page
    $xx = Page::factory([
      'slug' => 'virtual',
      'template' => 'newsletterlist',
      'model' => 'newsletterlist',
      'parent' => $this,
      'draft' => true,  
      'content' => [
        'title' => "TEST",
        'slug' => 'virtual',
        'recipients' => ""
      ]
    ]);

    $lists->add($xx);

    return $lists;
  }
}

```

In the pages section in the panel, there are only the three real pages visible.  
But if i say `text: '{{ page.lists.count }}'` i get `4` as result. There seems to be the forth page, but it’s not visible in the pages section list.

What could be the problem?

---

<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:** [October 2, 2020, 4:05pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/2 "2020-10-02T16:05:40Z")

</div>

Hm, as far as I know, virtual pages should be defined as children of a parent, so overriding the children method in the parent model, as described in the Virtual pages guide. Only then do they become part of the site index.

> **[Virtual pages](https://getkirby.com/docs/guide/virtual-pages)**
>
> In Kirby, you can integrate data from any data source and use them as if they were real Kirby pages, including creating and editing their content in the Panel.

---

<div class="post-metadata">

**Author:** ![andio](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andio/32/9117_2.png) [@andio](https://forum.getkirby.com/u/andio)\
**Post date:** [October 2, 2020, 4:11pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/3 "2020-10-02T16:11:15Z")

</div>

I don’t think so, because if i change the section type from `pages` to `info` i can clearly see, that there are 4 Page Objects in the returning Pages Object. I can even `dump` them and see them. It’s just the `pages` section is not displaying it, as if it only would display “real” pages(?).

I can not override the children method, because that is used for the real children. I need to add a second method which i called `lists` and query it like this in the blueprint:

```auto
      lists2:
        type: pages
        headline: Listen ({{ page.lists.count }})
        options: query
        pages: '{{ page.lists }}'

```

What is a strange thing: in the headline the count is 4. But there are only 3 items in the list:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/4/4ef624218b277df59c43994166f7f58e8f5d09b3.png)

---

<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:** [October 2, 2020, 4:18pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/4 "2020-10-02T16:18:32Z")

</div>

Hm, but a pages section cannot have a query or options. So your section ignores these settings and displays the children of the parent, which is the default.

Your virtual pages will only show up if they are part of the children.

---

<div class="post-metadata">

**Author:** ![andio](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andio/32/9117_2.png) [@andio](https://forum.getkirby.com/u/andio)\
**Post date:** [October 2, 2020, 8:22pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/5 "2020-10-02T20:22:52Z")

</div>

@texnixe I really don’t know what I would do without you sometimes 🙂 😂

You are absolutely right, the `pages` section doesn’t have `query` and `options` but you said that it has `parent`. And that was the key to success!

Here is the working solution:

blueprint:

```auto
    sections:
      lists2:
        type: pages
        headline: Listen ({{ page.lists.children.count }})
        empty: -
        parent: page.lists

```

In the model i have defined `lists` with this function:

```auto
  public function lists($options = null) {
    $lists = $this->childrenAndDrafts();
    $this->children()->add($lists);

    $xx = Page::factory([
      'slug' => 'virtual',
      'template' => 'newsletterlist',
      'model' => 'newsletterlist',
      'parent' => $this,
      'content' => [
        'title' => "TEST",
        'slug' => 'virtual',
        'recipients' => ""
      ]
    ]);
    $this->children()->add($xx);
    return $this;
  }
}

```

Basically i’m retrieving the children, adding these to the `lists`-method as den children, and then adding my own additional pages as often as needed - and returning this as the result.  
That works great:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/5/5e90a5b3692d5c2e407123907d190edc466f4e3a.png)

---

<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:** [October 2, 2020, 8:29pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/6 "2020-10-02T20:29:23Z")

</div>

Interesting, because the parent is supposed to be a single page, not a collection. Need to see this with my own eyes…

---

<div class="post-metadata">

**Author:** ![andio](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andio/32/9117_2.png) [@andio](https://forum.getkirby.com/u/andio)\
**Post date:** [October 2, 2020, 8:32pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/7 "2020-10-02T20:32:39Z")

</div>

The parent is a single page in this case, which has the children i want to display.

---

<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:** [October 2, 2020, 8:35pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/8 "2020-10-02T20:35:11Z")

</div>

Ah, alright, your function returns the page object, I didn’t read closely. Clever!

---

<div class="post-metadata">

**Author:** ![andio](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andio/32/9117_2.png) [@andio](https://forum.getkirby.com/u/andio)\
**Post date:** [October 2, 2020, 8:37pm UTC](https://forum.getkirby.com/t/how-to-virtual-pages-in-pages-section/19613/9 "2020-10-02T20:37:22Z")

</div>

This is a simple and good solution for me to add virtual pages to the collection in a `pages`-section. Perfect 🙂
