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?
I've found the errors:
class PluginSystemMyPlugin extends JPlugin {
function PluginSystemMyPlugin(&$subject, $config){
must to be:
class plgSystemMyPlugin extends JPlugin {
function plgSystemMyPlugin(&$subject, $config){
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
精彩评论