nabo Posted April 22, 2020 Share Posted April 22, 2020 Hello I configured the CMS multilanguage with a multisite idea. I created template "_site" and the name of the template is the url of the site interested. This installation is used only as API generator. The problem is that $page->url method returns the url with _site name. Now I have this situation /[language]/[_site name]/example/example... I would like to have this /[language]/example/example.... Is there a way to rewrite this method? The best solution could be a template type check that exclude the _site name in the result. This solution should work also when I select a page in CKEditor to set a link. Thanks Link to comment Share on other sites More sharing options...
Robin S Posted April 22, 2020 Share Posted April 22, 2020 6 hours ago, nabo said: Is there a way to rewrite this method? You hook Page::path - see Ryan's case study example: 6 hours ago, nabo said: with a multisite idea You might be reinventing the wheel... https://processwire.com/docs/more/multi-site-support/https://github.com/somatonic/Multisite/ 1 Link to comment Share on other sites More sharing options...
nabo Posted April 23, 2020 Author Share Posted April 23, 2020 Hi @Robin S I updated my ready.php including this wire()->addHookBefore('Page::path', function($event) { $page = $event->object; if($page->id === 1 || $page->template=="_site") return '/'; $path = ''; $parents = $page->parents(); foreach($parents as $parent) if($parent->id > 1 || $parent->template!="_site") $path .= "/{$parent->name}"; $event->return = $path . '/' . $page->name . '/'; }); but nothing different from usual happened... if I tried to log something there's also a Fatal Error Link to comment Share on other sites More sharing options...
Robin S Posted April 23, 2020 Share Posted April 23, 2020 A couple of issues I can see there. 46 minutes ago, nabo said: if($page->id === 1 || $page->template=="_site") return '/'; You need to set the $event->return instead of returning a value. And if you are hooking before and replacing a method with your own code then you need $event->replace = true. See Ryan's example in the topic I linked to. But in your case a simpler approach could be this (note that this is hooking after because it is modifying the $event->return): $wire->addHookAfter('Page::path', function(HookEvent $event) { $page = $event->object; if($page->rootParent->template != '_site') return; $event->return = str_replace('/' . $page->rootParent->name, '', $event->return); }); 2 Link to comment Share on other sites More sharing options...
nabo Posted April 23, 2020 Author Share Posted April 23, 2020 Hello @Robin S thank you very much, you save my day! ? 1 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