1

In Joomla 3 I had a really simple error.php file which pulled in the content from an article with the title '404'. I created an article named 404 and assigned it to a menu item of type 'single article' - also called 404. This means that the client can modify the article content from the front end if required and there is no need to access the error.php to make changes to the content.

This is the J3 code:

<?php
defined( '_JEXEC' ) or die( 'Restricted access');
if ($this->error->getCode() == '404') { 
    header ("HTTP/1.0 404 Not Found");
    echo file_get_contents(JURI::root().'?option=com_content&view=article&id=18');
    exit;
}
?>

Where id-18 is the id of the 404 article.

As in J3 in J4 I have created an article named 404 and assigned it to a menu item of type 'single article' - also called 404.

EDIT: NB - I am not using the site Cassiopeia, I have a custom template.

But in the error.php file I can't work out how the 'echo' line needs to change. I have tried this (and numerous other options) without success:

<?php
defined( '_JEXEC' ) or die( 'Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Router\Route;
use Joomla\CMS\HTML\HTMLHelper;

$app = Factory::getApplication();

$url = Route::_("index.php?option=com_content&view=article&id=154");

if ($this->error->getCode() == '404') { 
    header ("HTTP/1.0 404 Not Found");
    echo file_get_contents(Route::_('index.php?option=com_content&view=article&id=154'));  
    exit;
}
?>

But this results in this message:

"Warning: file_get_contents(/404): failed to open stream: No such file or directory in /home/[myroot]/[mydomain]/templates/mytemplate/error.php on line 14".

So what do I need to do?

1
  • Though it won't resolve your issue, you can feed your file contents directly into exit() instead of echo then exit.
    – mickmackusa
    Nov 7, 2021 at 1:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.