markus_blue_tomato Posted March 26, 2020 Share Posted March 26, 2020 We had the need, that the URL of some pages should only be some kind of ID. I know that there are Modules like https://modules.processwire.com/modules/process-redirect-ids/, but since we have a kind of ProCache based Static Page Generator this modules doesn't work for us. So we created this module, which hides the name filed on pages with specific templates and which replaces the $page->name with the $page->id. https://github.com/blue-tomato/PageUseIdAsName 2 Link to comment Share on other sites More sharing options...
adrian Posted March 26, 2020 Share Posted March 26, 2020 The way other is to simply change the name of the page to match the ID is a hook in your ready.php // rename page to match its page ID $this->wire()->addHookAfter('Pages::added', function($event) { $p = $event->arguments[0]; if($p->template != 'basic-page') return; $p->setAndSave('name', $p->id); }); One thing to note in your module - you are hooking on "save", so it will rename it every time it is saved. If you need the other functionality of your module, perhaps you can change to Pages::added ? 1 Link to comment Share on other sites More sharing options...
markus_blue_tomato Posted March 26, 2020 Author Share Posted March 26, 2020 I was looking for Pages::added but didn't found it (only Page::setupNew, which didn't do that in the way I want) ?Sure, maybe I'll change that soon. Link to comment Share on other sites More sharing options...
adrian Posted March 26, 2020 Share Posted March 26, 2020 7 minutes ago, Markus (Blue Tomato) said: I was looking for Pages::added but didn't found it (only Page::setupNew, which didn't do that in the way I want) ?Sure, maybe I'll change that soon. Don't forget Tracy's Captain Hook panel ? 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