1

I'm looking for a way to have a custom 404 error page that will appear in function of the language of the site.

So far I have created my error.php and I put it there : "templates/YourTemplate/error.php"

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

I also created my hidden menu with a blog view set to all language with the alias error-404. This menu to the articles from the "error-404" category (all language).

I can't have to alias for the same article so created the French article with error-404 and I also created the English categories with error-404-en alias. Finally, I created an association to link the two article together.

I have set every element to "no index / no follow".

I know that I could create a new template for one language and set the other one for the other language with their specific error.php, but I would like to keep the same template for both languages.

Thanks for your help!

5

you also could use the standard 404 (or similar) php-file of your template if it already exists. The Joomla! alias standard would be /404 or /404.html according to the global configuration for the alias handling. Normally it´s no good idea to override this behaviour by hand.

I would just use

<?php echo JText::_('SOME_INFO_FOR_404'); ?>

inside the php-file. So you just need to set up the according language string overrides for title etc. and do not need separated php-files or templates. If you do want to push special vars for the different languages, for e.g. passing different pictures, you could also use the available framework language checks.

  • PHP + language file is how I remember a commercial template doing it. It worked and was simple to localize. IIRC (has a BIG if) – Ville Niemi Feb 1 '16 at 23:33
  • @Ville Niemi You do not need a commercial template for that, Joomla itself replaces the JText items. Just use the override.ini for the replacements (available also at backend via Extensions -> Language -< Overrides), according to your used language(s). – PCo Feb 13 '16 at 15:49
1

Based on:

How to detect the current language of a Joomla! website?

Creating a Custom 404 Error Page

$lang = JFactory::getLanguage();

$result = $lang->getTag();

if (($this->error->getCode()) == '404') {

  if ($result=="en-GB") { 
      header('Location: /index.php?option=com_content&view=article&id=31');
      exit;
  }
  if ($result=="pt-PT") {
      header('Location: /index.php?option=com_content&view=article&id=30');
      exit;
  }

}

You must adapt your code, please read 'Creating a Custom 404 Error Page'

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.