Jonathan Lahijani Posted April 20, 2020 Share Posted April 20, 2020 I'm trying to intercept a 404 error page and have it render another page based on some general logic: The following is in /site/init.php: $this->addHookBefore('ProcessPageView::pageNotFound', function($event) { $url = $event->arguments('url'); // ensure trailing slashes if($url[-1] !== "/") $this->session->redirect(substr(wire("config")->urls->root, 0, -1).$url."/"); $p = wire('pages')->get("/sites/".wire('config')->site.$url); if($p->id) { $event->replace = true; $event->return = $p->render(); } else { $event->replace = false; } }); Given my setup, $p->render() will cause an error related to it not finding a custom function I have defined in my /site/templates/_init.php: Call to undefined function myWeirdFunction() How do I properly render the file and make sure the chain of included files is correct? This is always a little confusing to me. Link to comment Share on other sites More sharing options...
adrian Posted April 21, 2020 Share Posted April 21, 2020 Maybe something useful in here?https://github.com/adrianbj/ProcessRedirectIds/blob/master/ProcessRedirectIds.module 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