Page() helper for virtual pages?

I have translated urls in my multi language site. How do I link to an specific page in the front end in the current language?

the link is across site so I can’t use $page->url(). I tried page('registro')->url('es') using the id, ui, translated url. I get Call to a member function url() on null.

Did you try like that: $page->url('es');

Or you can use with default language id:


I did try page('register')->url('es'); with the translated url/slug for both languages. $page->url('es'); works has spected but I want to use the link in other templates so it would not do the work.

It seems it does not work because it’s a virtual page. <?= page('otherid')->url($kirby->languageCode()) ?> works with other pages but not with this one, which is a virtual one. Is this a bug?

You may be right.

@texnixe How do we access virtual pages? page('virtual_id') is not working :thinking:

Even with the same slug the page() helper doesn’t work. If you dump() the parent, you won’t see the virtual page listed has a child. So I guess it doesn’t work because they are virtual, but then how can we access it in a similar way to page()? :thinking:

How did you define the virtual page? Virtual pages only defined in a route don’t act like real pages.

Only on route, following this guide for simple virtual page.

Then you can’t use the page helper, but have to call the URL manually.

$site->url($languageCode) . '/registration'
1 Like

You might want to look into using the pages extension and register the page like explained here:

If you do it like that, the page becomes a part of the site and acts like a normal page.

1 Like

I think I’ll use pages that physically exist in the file system for now then and try that later. thanks!