Expanding on Simple route for year in blog url I need to use this on multiple language site.
Only thing that doesn’t work at the moment is switching languages on the blog-item page.
In my config:
'routes' => [
[
'pattern' => 'blog/(:num)/(:any)',
'language' => '*',
'action' => function ($language, $year, $slug) {
return site()->visit('blog/' . $slug);
}
],
[
'pattern' => 'blog/(:any)',
'language' => '*',
'action' => function ($language, $uid) {
$page = page('blog')->children()->find($uid);
if ( $page ) {
return site()->visit('blog/' . $page->date()->toDate('Y') . '/' . $page->slug());
} else {
$this->next();
}
}
]
]
My page model has not changed but I’m not sure if or how to change:
<?php
class BlogItemPage extends Page {
public function url($options = null): string {
// Add year to the url
return $this->url = $this->parent()->url() . '/' .
$this->date()->toDate('Y'). '/' . $this->uid();
}
}