Serafino Bilotta
Serafino Bilotta

Reputation: 51

addScript() not work on Joomla System Plugin

I'm developing a Joomla system plugin and I need to add some scripts in the header, I've the following code:

defined('_JEXEC') or die('Restricted access');

jimport('joomla.plugin.plugin');

class PluginSystemMyPlugin extends JPlugin {
    function PluginSystemMyPlugin(&$subject, $config){
        parent::__construct($subject, $config);
        $this->_plugin = JPluginHelper::getPlugin('system','myplugin');
        $this->_params = new JParameter($this->_plugin->params);
        $this->_mainframe= &JFactory::getApplication();
        if($this->_mainframe->isAdmin())return;
    }
    function onAfterInitialise(){
        if($this->_mainframe->isAdmin())return;
        $loadjquery = $this->params->get('loadjquery');
        $document =& JFactory::getDocument();
        if($loadjquery=='yes'){
            JHTML::_(' behavior.mootools');
            $document->addScript("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js");
        }
        $document->addScriptDeclaration('
            jQuery.noConflict();');
    }
}

I've also tried addScriptDeclaration(), addStyleSheet(), addStyleSheetDeclaration(), none working. My Joomla version is 1.5.23. I've tried others plugin with the same declarations in onAfterInitialise() and they worked, why not mine?

Upvotes: 0

Views: 1328

Answers (2)

Ruslan Polutsygan
Ruslan Polutsygan

Reputation: 4461

Have you installed it correct? Have you published it? Are you sure that your plugin is run? Have you tried to debug your plugin code with die function to detect whether it works? Also you could try this http://docs.joomla.org/JDocumentHTML/addCustomTag

Upvotes: 0

Serafino Bilotta
Serafino Bilotta

Reputation: 51

I've found the errors:

class PluginSystemMyPlugin extends JPlugin {
    function PluginSystemMyPlugin(&$subject, $config){

must to be:

class plgSystemMyPlugin extends JPlugin {
    function plgSystemMyPlugin(&$subject, $config){

Upvotes: 1

Related Questions