Hi guys!
I’m working with the new Kirby Starterkit on my Mac for the first time. I’m not a programmer, but I’ve successfully removed the blog folder name with the route solution. Nice
But, the blog home page, however, continues to include the folder /blog/ on the URL, see here:
I can remove it permanently?
Thanks in advance for your help!
texnixe
November 20, 2016, 4:37pm
2
2 Likes
If I want to remove also the /projects/ folder on project URL, for example, creating another route (identical as /blog/) give me an error, how can I do?
In short: after creating the page model for the project (that works), what route I put in config.php?
texnixe
November 20, 2016, 10:38pm
5
This should work:
c::set('routes', array(
array(
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('blog/' . $uid);
if(!$page) $page = page('projects/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
),
array(
'pattern' => 'blog/(:any)',
'action' => function($uid) {
go($uid);
}
),
array(
'pattern' => 'projects/(:any)',
'action' => function($uid) {
go($uid);
}
)
));
3 Likes
Yes, it works well. Thanks
For flexibility, in case I want translate the portfolio into another language , no longer works properly this code. For example:
EN: domain.com/project-a
DE: domain.com/de/projekt-a
The page models + routes changes here, how can I do in this situation?
Also for the blog changes:
EN: domain.com/licensing
DE: domain.com/de/lizenzierung
Thanks for the help.
Can someone help me? Thanks
texnixe
November 22, 2016, 2:52pm
8
Unfortunately not, I’ve never managed to get multi-lang routes with URL-Keys working. I’ve invited @lukasbestle to this thread.
Ok, thanks for the support.
This is untested, but inspired by the code Kirby actually uses internally:
$redirectionRoute = function($uid) {
$site = site();
$lang = kirby()->route->lang;
$page = $site->visit($uid, $lang);
if(!$page) $page = $site->visit('blog/' . $uid, $lang);
if(!$page) $page = $site->visit('projects/' . $uid, $lang);
if(!$page) $page = $site->visit($site->errorPage(), $lang);
return $page;
};
c::set('routes', array(
array(
'pattern' => 'blog/(:any)',
'action' => function($uid) {
go($uid);
}
),
array(
'pattern' => 'projects/(:any)',
'action' => function($uid) {
go($uid);
}
),
array(
'pattern' => 'de/(:any)',
'action' => $redirectionRoute,
'lang' => 'de'
),
array(
'pattern' => '(:any)',
'action' => $redirectionRoute,
'lang' => 'en'
)
));
1 Like
texnixe
November 22, 2016, 9:14pm
11
Hm, that does not seem to work . Will try again tomorrow with a fresh kit.
Thank you, it does not work
Turns out there was just a small issue with the code. This code works for me (I also made some further improvements):
$visitRoute = function($uid) {
$site = site();
$lang = kirby()->route->lang;
$page = $site->visit($uid, $lang);
if($page === $site->errorPage()) $page = $site->visit('blog/' . $uid, $lang);
if($page === $site->errorPage()) $page = $site->visit('projects/' . $uid, $lang);
return $page;
};
c::set('routes', array(
array(
'pattern' => '(?:blog|projects)/(:any)',
'action' => function($uid) {
go($uid);
}
),
array(
'pattern' => '(?:de/blog|de/projects)/(:any)',
'action' => function($uid) {
go('de/' . $uid);
}
),
array(
'pattern' => 'de/(:any)',
'action' => $visitRoute,
'lang' => 'de'
),
array(
'pattern' => '(:any)',
'action' => $visitRoute,
'lang' => 'en'
)
));
Of course you will need to adapt the code if your projects
or blog
page has a URL key in German. It works with URL keys for the individual children, but not for the parent currently.
2 Likes
Thank you Lukas for your solution