Return virtual Page from route

Try to return a virtual Page from a route like so:

`return new Page([
    'slug' => 'my-slug',
    'template' => 'my-template',
    'content' => $my_data

Kirby sends me this friendly message: “Too few arguments to function PageAbstract::__construct(), 1 passed liste.php on line 67 and exactly 2 expected.”

Any Ideas, anyone? :slight_smile:

Virtual Pages are a new feature in Kirby 3, but you created the topic in the Kirby 2 category. Which Kirby version are you using exactly? :smiley:

I unfortunately have to work with Kirby 2 for this project - and my hope was that Kirby 2 has a similar approach.

What you could do is create a parent page in the filesystem and then return that page with your data for the route. What is your exact use case?

I return my template and my data this way:

`return array('mylist-publish', $my_data);`

In Kirbys /content/ folder I create a folder named ‘mylist-publish’ and a empty file ‘mylist-publish.txt’… so this works fine - (is that what you mean with “parent page”???). My plugin uses a bunch of routes and templates… My idea was to eliminate the additional folders and files in /content/ and work with a virtual Page instead… that was my daydream :blush:

Ps. My plugin is almost finished

Yes, that’s what I meant. Then you can return this page over and over again for different routes with additional data. Downside is that the UID is always the same.

The alternative would be to load a template, but then you have to pass all data to the template and down to all snippets, which is a pain in the neck.

1 Like