Happy New Year!
I have a multi-language site and a custom route which creates a virtual page under the parent jobs. Navigating the virtual pages works as expected. On the virtual page I render a language switcher using the below snippet. For some reason on a virtual page the url() helper does not include the language part. For example on a virtual page a link would be /jobs/my-job-id where on a non-virtual page it would include the language code /en/jobs/my-job-id. Anyone have an idea or what I’m doing wrong?
language-switcher.php
<el-options>
<?php foreach ($kirby->languages() as $l): ?>
<?php
// Build URL preserving current query string
$url = url($page->uri(), [
'language' => $l->code(),
'query' => $_GET ?? []
]);
?>
<el-option value="<?= $l->code() ?>" >
<a href="<?= $url ?>"></a>
</el-option>
<?php endforeach ?>
</el-options>
custom-route.php
<?php
return [
[
'pattern' => 'jobs/(:any)',
'language' => '*',
'action' => function ($language, $jobID) {
// Create a virtual page
$virtualPage = Page::factory([
'slug' => Str::slug($jobID),
'template' => 'job',
'model' => 'job',
'parent' => page('jobs')
]);
return site()->visit($virtualPage, $language);
}
],
];
Thanks!