Hi all!
I dug into the form threads but did not find a suitable answer for kirby v3.
Basically i want to hide the url-slug for my page “landingpages” and access the children directly from root. in my non multi-lang setup, i use a model to return “just the uid” when using the url function. In the router, i use these patterns, which search the page based on the uri given.
[
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('landingpages/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
],
[
'pattern' => 'landingpages/(:any)',
'action' => function($uid) {
go($uid, 301);
}
]
I assume the model will work with the uri method, since it returns the translated slug. But i can’t get my router to work properly. I thought i could find my page by uri or slug, but neither does work. Does anybody has an idea how to find the page by translated slug in the router?
[
'pattern' => '(de/|de)?(:any)',
'action' => function($lang, $uid) {
$language = trim($language, '/');
if(!$language) $language = 'en';
$page = page($uid);
if(!$page) $page = pages()->findBy('slug', $uid); --> Does not work.
if(!$page) $page = pages()->findByUri($uid); --> Does not work.
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
]
Little Update
I also tried implementing the example from the docs. This does work in english and also in german for the “normal” pages, but the subpages of “landingpages” are not found either.
[
'pattern' => '(:any)',
'language' => 'en',
'action' => function($language, $slug) {
if (page($slug)) {
return $this->next();
}
if ($page = page('landingpages/' . $slug)) {
return $page;
}
return false;
}
],
[
'pattern' => '(:any)',
'language' => 'de',
'action' => function($language, $slug) {
dump($slug);
if (page($slug, $language)) {
return $this->next();
}
if ($page = page('landingpages/' . $slug, $language)) {
return $page;
}
return false;
}
]