owzim Posted October 14, 2017 Posted October 14, 2017 Hi, is there a way to change that behavior? Can I hook into that somehow? Thanks!
owzim Posted October 14, 2017 Author Posted October 14, 2017 Thanks, unfortunately this gives my only ''access not allowed" as a $reason, so if I would overwrite the behavior via hook, based on that, I would mess with all kinds of access management.
adrian Posted October 14, 2017 Posted October 14, 2017 Maybe it would help to know a little more about your scenario. Perhaps you could try Page::viewable - it checks to see if a template file exists? 2
abdus Posted October 14, 2017 Posted October 14, 2017 $reason parameter looks like it's for internal use $page = $this->checkAccess($page); if(!$page || $_page->id == $config->http404PageID) { return $this->pageNotFound($_page, $this->requestURL, true, 'access not allowed'); } Why do you need $reason for?, if you want to narrow down 404s to missing template files than you can use wire()->addHookBefore('ProcessPageView::pageNotFound', function (HookEvent $e) { $page = $e->arguments('page'); if ($page->id && !$page->template->filenameExists()) { // page exists, but template file does not } }); 2
owzim Posted October 14, 2017 Author Posted October 14, 2017 Thanks, ProcessPageView::pageNotFound is definitely the right spot, I came up with this method, don't know if it has any access rights implications: public function hook_ProcessPageView_pageNotFound(HookEvent $event) { $page = $event->arguments('page'); $page->template->filename = 'path/to/existing/file'; if ($page->viewable()) { $event->return = $page->render(); $event->replace = true; } } Page render actually outputs something, because I hook into it. But just not with a template file.
adrian Posted October 14, 2017 Posted October 14, 2017 I am worried that there won't be any 404 responses to any requests to your site though. It still feels like it's the wrong solution to whatever the problem is, but maybe I am not understanding the use case. 1
owzim Posted October 14, 2017 Author Posted October 14, 2017 I want to render pages without the need of a template file. 404s still work.
abdus Posted October 14, 2017 Posted October 14, 2017 24 minutes ago, owzim said: $event->return = $page->render(); 4 minutes ago, owzim said: I want to render pages without the need of a template file. If you want to use $page->render(), then $page has to have a template file, but if a page is viewable (i.e. has a template file) you won't get a 404 error. I'm not sure you can have both. If you want the same template file for multiple templates, then you can set it so in template settings > File tab 1
Robin S Posted October 14, 2017 Posted October 14, 2017 21 minutes ago, owzim said: $page->template->filename = 'path/to/existing/file'; Instead of the hook, wouldn't it be better to set this as the "Alternate template filename" only on the templates you need it for? 1
owzim Posted October 14, 2017 Author Posted October 14, 2017 Just now, Robin S said: Instead of the hook, wouldn't it be better to set this as the "Alternate template filename" only on the templates you need it for? That is also an option I thought about, but this is for a module I am creating and I don't want users of that module to jump through those hoops.
owzim Posted October 14, 2017 Author Posted October 14, 2017 3 minutes ago, abdus said: If you want to use $page->render(), then $page has to have a template file, but if a page is viewable (i.e. has a template file) you won't get 404 error. I'm not sure you can have both. If you want to use same template file for multiple templates, then you can set it so in template settings > File tab The rendering ($page->render()) is taken care of elsewhere.
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