a-ok Posted March 11, 2020 Share Posted March 11, 2020 I'm currently appending page names, with a specific template, with a date. This works fine but as I have multi-languages set up it only appears (unless my code is wrong) to be applying it to the default language page name. Any thoughts on where I'm going wrong? function customPageName(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'about-events-single') { $eventDate = date("dmY", $page->global_date_end); $pageName = wire()->sanitizer->pageName($page->title . '-' . $eventDate, true); $page->setOutputFormatting(false); $page->name = $pageName; } } wire()->addHookAfter('Pages::saveReady', null, 'customPageName'); Link to comment Share on other sites More sharing options...
MoritzLost Posted March 11, 2020 Share Posted March 11, 2020 You need to iterate through all languages and set the name in all of them. After all, they might also have different titles, so you want to use the local title as well. Something like this: function customPageName(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'about-events-single') { $eventDate = date("dmY", $page->global_date_end); $page->of(false); foreach (wire('languages') as $lang) { $localTitle = $page->getLanguageValue($lang, 'title'); $localPageName = wire()->sanitizer->pageName($localTitle . '-' . $eventDate, true); $page->setLanguageValue($lang, 'name', $localPageName); } } } wire()->addHookAfter('Pages::saveReady', null, 'customPageName'); Quick and untested, might need some adjustments, but you get the idea ? 2 Link to comment Share on other sites More sharing options...
a-ok Posted March 11, 2020 Author Share Posted March 11, 2020 4 hours ago, MoritzLost said: Quick and untested, might need some adjustments, but you get the idea ? Much appreciated ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now