VirtualPages in Pages Field

Hello!
When passing VirtualPages to a PagesField Kirby will not store any value in the content file the field belongs to.

A collection of VirtualPages is passed to to the field by a custom site method. This happens within a multilanguage installation.

# Page Blueprint with the pages field
fields:
  virtualPagesselect:
    type: pages
    query: site.virtualPagesCollection
// site/plugins/virtualpages/index.php

Kirby::plugin('namespace/virtualpages', [
    'siteMethods' => [
        'virtualPagesCollection' => fn () => Pages::factory([
			[
				'slug' => 'virtual-slug',
				'template' => 'virtual',
				'parent' => kirby()->site(),
				'model' => 'virtual-page',
				'translations' => [
					'de' => [
						'code' => 'de',
						'content' => [
                    		'uuid' => 'virtual-id',
                    		'title' => 'VirtualPage',
                		],
					],
					'en' => [
						'code' => 'en',
						'content' => [
                    		'title' => 'VirtualPage',
                		],
					],
				]
			]
		]),
    ],
]);

I’ve cleared the UUID cache before each test and can see that, when the pages field request the virtual collection, the uuid cache folder is populated the virtual page uuids.

1 Like

Part of your post seem to be missing.

How do you define your virtual pages? Are they somewhere located/connected with the site index?

Sorry Nico. Was hitting tab key to indent and then return which submitted the the question way before i finished writing it!

I guess the way forward would be to create PageModel for a real page, overwriting the children method to return a pages collection of virtual pages so kirby()->page($id) can pick it up.

Exactly. Currently your virtual pages exist only in their own space, but no way for the site to find them.

1 Like