Fuzzy Posted May 28, 2018 Share Posted May 28, 2018 Hi there, Can't find a solution for this problem (although it sounds quite easy): If a page exists but is not active in the current user's language there should be an alert with "content not available for your selected region" instead of displaying the 404-page. I tried this: // if page is not active in current user language show alert, instead of 404 page if($page->name != 'http404' && !$page->viewable($user->language)) { $page = $pages->get('id=17104'); // this is the page containing the content-not-available-in-your-region-message } It works when logged in as superuser but when loged out, visitors will always be redirected to the 404-page. Can anyone help, please? Link to comment Share on other sites More sharing options...
Sergio Posted May 28, 2018 Share Posted May 28, 2018 You may need a hook to get it done, take a look on this thread: 1 Link to comment Share on other sites More sharing options...
kixe Posted May 28, 2018 Share Posted May 28, 2018 Try this hook in hook $this->addHookBefore('PageRender::renderPage', function($e) { $event = $e->arguments[0]; $page = $event->object; $user = $this->wire('user'); // QUICK EXIT if ($user->isSuperuser()) return; // superuser if (!empty($page->template) && $page->template->id == 2) return; // backend if ($user->language->isDefault()) return; // default language $language = $user->language; $currentLanguageStatus = $page->get("status$language"); if ($currentLanguageStatus == 0) { $otherPage = $this->wire('pages')->get(1234); // get page to be rendered instead $event = new HookEvent(array('object' => $otherPage)); $e->arguments(0, $event); } }); 3 Link to comment Share on other sites More sharing options...
Fuzzy Posted May 30, 2018 Author Share Posted May 30, 2018 Thanks @kixe and @Sergio for trying to help me. I've added @kixe's code at the top of my prepend.inc (and changed the page id) but the 404 is still displayed. I also tried ProcessPageView::pageNotFound instead of PageRender::renderPage - but without success! Any ideas? Link to comment Share on other sites More sharing options...
kixe Posted May 30, 2018 Share Posted May 30, 2018 @Fuzzy Place this code in /site/ready.php Create this file if it doesn't exist. Link to comment Share on other sites More sharing options...
Fuzzy Posted May 30, 2018 Author Share Posted May 30, 2018 I'm trying here, but no luck so far. Link to comment Share on other sites More sharing options...
Fuzzy Posted June 6, 2018 Author Share Posted June 6, 2018 Hi @kixe, Sorry to bother you again. Could you please check your code again? I get the following error Error: Class 'ProcessWire\HookEvent' not found (for this line $event = new HookEvent(array('object' => $otherPage)); ) PS: Sorry, I'm still learning and have to admit that hooks are out of my range... 1 Link to comment Share on other sites More sharing options...
kixe Posted June 6, 2018 Share Posted June 6, 2018 I tested my code and it works. Maybe there is a namespace issue. Which PW Version do you use? Did you place the code in the right file and folder? Link to comment Share on other sites More sharing options...
Fuzzy Posted June 6, 2018 Author Share Posted June 6, 2018 ProcessWire 2.7.3 and code is placed in file ready.php which is in folder "site". I've only changes the page id... Link to comment Share on other sites More sharing options...
kixe Posted June 6, 2018 Share Posted June 6, 2018 Namespace problem. Somewhere in your files (ready.php?) the namespace ProcessWire is defined. You need to remove this. Don't mix files of installations (PW 3.0.x) using namespace with non namespace installations (PW 2.7 or 2.8) Link to comment Share on other sites More sharing options...
Fuzzy Posted June 6, 2018 Author Share Posted June 6, 2018 Still not getting it. Removing namespace Processwire from ready.php solved the error but the 404 is still being displayed. After some investigations included the following in config.php - but no effect... $config->templateCompile = false; $config->moduleCompile = false; Any ideas? 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