psy Posted November 26, 2019 Share Posted November 26, 2019 (edited) For pages with a particular template, I would like them to display/redirect to a different page from the normal http404 page when status is unpublished. Can't figure out what to hook and where. Un-working code is: <?php // in my auto-loaded custom module public function init() { // this hook doesn't catch... returns the normal http404 page for unpublished template=profile pages $this->addHookBefore('Page("template=profile")::loaded', $this, "unpublishedProfile"); } public function unpublishedProfile (HookEvent $event) { $page = $event->arguments(0); if ($page->isUnpublished()) $this->wire('session')->redirect($this->wire('pages')->get(1312)->url); } Also tried to hook After page loaded with same result, ie default Page Not Found shown. Help & suggestions to fix much appreciated. Cheers psy Edited November 26, 2019 by psy solved Link to comment Share on other sites More sharing options...
Zeka Posted November 26, 2019 Share Posted November 26, 2019 2 1 Link to comment Share on other sites More sharing options...
psy Posted November 26, 2019 Author Share Posted November 26, 2019 Thanks @Zeka, think you're onto something there. I searched but could not find Link to comment Share on other sites More sharing options...
psy Posted November 26, 2019 Author Share Posted November 26, 2019 Solved! Thanks @Zeka Solution: <?php // in my auto-loaded custom module public function init() { $this->addHookAfter('ProcessPageView::pageNotFound', $this, "unpublishedProfile"); } public function unpublishedProfile (HookEvent $event) { $page = $event->arguments(0); if ($page->isUnpublished() && $page->template == 'profile') $this->wire('session')->redirect($this->wire('pages')->get(1312)->url); } 2 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