4

I have some custom components that specify images either in CSS or inline with relative paths:

<img src=\"images/loader.gif\"> 

The problem is that I have a multi-site configuration (I don't use any 3rd party extensions) where the site is defined to be a specific language. So when you go to the site say www.anothersite.com it is Spanish only. When you go to a url Joomla puts in the locale code according to what I setup in the Language manager. ie.

www.anothersite.com/es/stuff

This is a problem with my custom components as now any images try to resolve to:

www.anothersite.com/es/images/loader.gif

Which is incorrect as it is at:

www.anothersite.com/images/loader.gif

I have English sites as well in my multi-site configuration so it is important to resolve to: www.anothersite.com/images/loader.gif or at least something consistent.

I don't want to incorporate the language switcher as each site needs to be a dedicated language plus I doubt that changes anything. I can certainly add the language locale to my code but that is not a very elegant solution. Is there a better way to do this?

1
  • I had the same problem, adding this code to correct the <base> was the correct solution. Thanks Commented Sep 27, 2017 at 14:59

2 Answers 2

3

I haven't been able to reproduce your error, but you can remove the language code from the Language Filter Plugin by setting "Remove URL Language Code to YES. That will remove the /es/ or /en/ part from your URL.

Language Filter Plugin

You can also use absolute paths in the component with the JURI::root() string:

<img src="<?php echo 'JURI::root()'; ?>images/loader.gif"> 
1

This is probably because of incorrect <base> tag value that is auto generated by Joomla in multi language setup when SEF and URL Rewriting are ON. You can fix it by removing the Joomla generated <base> tag and then adding a new one manually.

Open your template's index.php file, inside the <head> tag, after the <jdoc:include type="head" /> add this code :

<?php $doc = JFactory::getDocument(); unset($doc->base); ?> <base href="<?php echo JURI::root(); ?>"> 

Tested with Joomla 3.6.5

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.