sanstraces Posted July 14, 2017 Share Posted July 14, 2017 hallo! i'm new to processwire. i try to append the page id to the page name with a hook, when the page is added. so it looks like page-id. i used addHookAfter('added') for this, but its not working. public function hookAfterAdded($event) { $page = $event->arguments[0]; $page->name = $page->name .'-'. $page->id; $this->message('added '.$page->name); } any idea to solve the problem! Thanks - sanstraces - Link to comment Share on other sites More sharing options...
PWaddict Posted July 14, 2017 Share Posted July 14, 2017 I'm not familiar with hooks but if you want you can try the Setup Page Name module to do what you want. Link to comment Share on other sites More sharing options...
Klenkes Posted July 15, 2017 Share Posted July 15, 2017 I think the problem is that in the moment of adding the new page the ID ist not known yet. So, the logical steps would be: add the page and then rename it. The issue has been discussed before. 1 Link to comment Share on other sites More sharing options...
Robin S Posted July 15, 2017 Share Posted July 15, 2017 Welcome @sanstraces You need to save the page after you set the name. public function hookAfterAdded($event) { $page = $event->arguments[0]; $page->name = $page->name .'-'. $page->id; $page->save(); $this->message('added '.$page->name); } Normally the $page->setAndSave() method is useful in these situations, but there seems to be a bug when saving the page name. 1 Link to comment Share on other sites More sharing options...
adrian Posted July 17, 2017 Share Posted July 17, 2017 @sanstraces - depending on your actual needs, this might also be an option: 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