I’ve got a pages section, where the pages are queried from page.lists
In the model i defined:
<?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.
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.
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:
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.
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: