Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

joomla plugin extension loads css file on every page

I'm using a custom plugin extension with Joomla 2.5. This plug-in is targeted for a single page on my site. But for some reason I noticed it loads the css file on every single page.

The code for the plugin loads this css file:

$doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');

I don't assume this is common but I'm not sure about plugins. Can I make it only apply the the page I want instead of every single page. Any thoughts on how to debug this would be appreciated.

The plugin prints a simple table on an article page and uses the plugin function onContentPrepare

like image 404
Tom Avatar asked Nov 24 '12 18:11

Tom


1 Answers

Use these snippets to manage your problem:

1) Load CSS by checking the active menu item

$menu = &JSite::getMenu();
$menuItem = $menu->getActive();
$Itemid = $menuItem->id;
if($Itemid!=1)
{
 $doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');
}

2)Load CSS upon component

if (JRequest::getCmd( 'option' ) == 'com_k2'){
        $doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');
}

3)Load CSS only in home page

<?php if(JRequest::getInt('Itemid') == $menu->getDefault()) {
   $doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');
}?>

4)Load CSS upon active menu id

<?php
$menuID = JSite::getMenu()->getActive()->id ;
  if ($menuID == '6')
  {
   $doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');
  }
?>

5)Load CSS upon active language:

$lang =& JFactory::getLanguage();
switch ($lang) {
case 'en-gb':
$doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');
break;
}

6)Load CSS upon users

$user =& JFactory::getUser();
if($user->get('id')==0){
//user is logged in
 $doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');
}

7)Load CSS upon URL

$u =& JFactory::getURI();
if($u=="http://www.example.com/joomla/index.php?task=view&id=12&Itemid=29")
{
$doc->addStyleSheet($pluginAssetsUrl . '/css/aecuserpage.css');
}
like image 129
vorillaz Avatar answered Oct 11 '22 23:10

vorillaz