Multilang Virtual Page

Hi all.

I have a multilang setup and want to build virtual pages from a .json source (which is coming from another Kirby installation). I am using a page model to set everything up.
I got quite far and the virtual pages are actually displayed in the panel on the parent page. However, when I try to enter one of the pages, I get a 404 β€” Not found error. What am I doing wrong?

Here is my model:

<?php

class KvdatesPage extends Page
{
    public function children()
    {
        $site = kirby()->site();
        $pages   = [];
        $request = Remote::get($site->getKgb(false, 'kv', 'url') . '/termine.json');
        $events = json_decode($request->content());

        foreach ($events as $event) {
            $translations = [];
            foreach ($event->translations as $translation) {
                $translations[$translation->code] = [
                    'slug' => $translation->slug,
                    'code' => $translation->code,
                    'content'  => [
                        'title' => $translation->title,
                        'num' => $translation->num,
                        'duration' => $translation->duration,
                        'startDate' => $translation->startDate,
                        'location' => $translation->location,
                        'banner' => $translation->banner
                    ]
                ];
            }
            $pages[] = [
                'slug' => $translations['de']['slug'],
                'template' => 'event',
                'model'    => 'event',
                'translations' => $translations
            ];
        }

        return Pages::factory($pages);
    }
}

It might be possible that you have to define a parent in your pages factory so that the system knows where to locate your virtual pages. Like return Pages::factory($pages, $site->find('your-parent')).

This might be helpful: How to add virtual pages to kirby's index

Thanks so much @nilshoerrmann , that was it.
All that was missing was to add the parent to the factory method like so:

return Pages::factory($pages, $this);

1 Like