Search code examples
concrete5concrete5-5.7

Programmatically render 404 in single page in concrete5 (version 7)


I've got a single page, where it checks a slug. If this slug can not be found in a database table, the single page should render the 404 page.

Something like this I have tried:

$this->render('/page_not_found');

Now, this goes to your active package single pages directory (packages/your_pkg_handle/single_pages/page_not_found.php). It should go to the active theme instead though... I have tried setting the second parameter to "null", as I thought that would be the pkgHandle, but no result. Obviously I'm missing something or this is not possible?


Solution

  • Try

    $this->replace('/page_not_found');
    

    instead.

    This is a little convoluted, but the reasoning behind this is $this->render() actually renders the view with the current controller (which will mean looking into the package for the view), whereas $this->replace() will replace the rendering session entirely with a new controller, view and exit output.