chrizz Posted June 10, 2019 Share Posted June 10, 2019 I already checked the CaptainHook cheatsheet - only the httpUrl method for PageFiles is hookable. It looks as if hooking the counterpart for pages is not possible ? I currently use httpUrl at many places in the code but the URLs need to be rewritten. When hooks are not appropriate: Is there a way to add a custom method for all pages (e.g. $page->myCustomPath()) which actually returns the URL I need? Link to comment Share on other sites More sharing options...
bernhard Posted June 10, 2019 Share Posted June 10, 2019 https://processwire.com/docs/modules/hooks/#how-can-i-add-a-new-method-via-a-hook 2 1 Link to comment Share on other sites More sharing options...
chrizz Posted June 10, 2019 Author Share Posted June 10, 2019 whoop. Perfect! Thanks for that link ? Link to comment Share on other sites More sharing options...
Robin S Posted June 10, 2019 Share Posted June 10, 2019 When you want to change a page's url or httpUrl in a hook you do this by hooking Page::path - the URLs are derived from the path. The classic post about this is Ryan's CMSCritic case study: So for a hook like this... $wire->addHookBefore('Page::path', function(HookEvent $event) { $page = $event->object; if($page->template == 'news_item') { $event->replace = true; $event->return = "/my-custom-path/$page->name/"; } }); ...the results are... 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