afforever wrote:after searching this forum i couldn't find a solution which is that i want to load a different css or javascript file for a specific module or plugin based on the language selected. So far this worked for the language direction only
Code: Select all
$lang = JFactory::getLanguage();
if ($lang->isRTL()) {
JHtml::_('stylesheet', 'mod_mymodule/css/mycss.css', array(), true);
JHtml::_('script', mod_mymodule/js/myjs.js', true, true);
}
it works perfectly for the language direction but not for a specific language. Right now i have two different rtl languages each having different settings.
Use this type of code:
Code: Select all
$lang = JFactory::getLanguage();
if ($lang->getTag() == 'en-GB') {
whatever code
} else {
etc.
As I explained, this code
Code: Select all
JHtml::_('stylesheet', 'mod_mymodule/css/mycss.css', array(), true);
JHtml::_('script', mod_mymodule/js/myjs.js', true, true);
will work fine IF the files are present in
ROOT/
media/mod_mymodule/css/mycss.css
ROOT/
media/mod_mymodule/js/myjs.js
Another possible code would be:
Code: Select all
$doc = JFactory::getDocument();
$doc->addScript(JURI::base().'../media/mod_mymodule/css/mycss.css');
$doc->addScript(JURI::base().'../media/mod_mymodule/js/myjs.js');
For a plugin, you may want to first make sure that one is in the right application:
Code: Select all
$app = JFactory::getApplication();
if ($app->isSite()) {
etc.
This means that you have to add in your module or plugin xml, after <files></files> and depending on your needs
Code: Select all
<media destination="mod_mymodule" folder="media">
<filename>index.html</filename>
<folder>css</folder> <!-- Note: if needed -->
<folder>images</folder> <!-- Note: if needed -->
<folder>js</folder> <!-- Note: if needed -->
</media>