I'm having a real problem unstanding somthing thats probably very easy about creating and using joomla plugins.
Here is what I've done so far.
I've created a sample joomla plugin using the following two files inside of a folder and named them all the same.
I listed their contents below.
The plugin installs correctly through the admin panel
Then I enable it through plugin manager
ok. all set to go.
How do I use the plugin on an article once I've enabled the plugin?
ZIP FOLDER: MakePlugIn FOLDER: MakePlugIn
MakePlugIn.php -
<?php
// No direct access allowed to this file
defined( '_JEXEC' ) or die( 'Restricted access' );
// Import Joomla! Plugin library file
jimport('joomla.plugin.plugin');
//The Content plugin MakePlugIn
class plgContentMakePlugIn extends JPlugin
{
function plgContentMakePlugIn (&$subject)
{
parent::__construct ($subject);
}
function onPrepareContent (&$article, &$params, $page=0)
{
print "I am a happy plugin";
}
}
?>
MakePlugIn.xml -
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="content">
<name>Make-Plug-In</name>
<author>Make-Plug-In</author>
<creationDate>03/15/2011</creationDate>
<copyright>Copyright (C) 2011 Holder. All rights reserved.</copyright>
<license>GNU General Public License</license>
<authorEmail>authoremail@website.开发者_StackOverflow中文版com</authorEmail>
<authorUrl>www.authorwebsite.com</authorUrl>
<version>1.0</version>
<description>Make-Plug-In test</description>
<files>
<filename plugin="MakePlugIn">MakePlugIn.php</filename>
</files>
</install>
You should not be echo
ing or print
ing information in the plug-in.
The method is receiving article reference as a parameter, modify it and you are good. You can use var_dump
to quickly identify proper object type and properties.
Here is Joomla tutorial on creating Content Plug-in.
Updated on 3/17/2011
This is in response to first comment.
In order to modify the article modify the value of referenced object &$article
.
See example below:
function onPrepareContent( &$article, &$params, $limitstart )
{
// Include you file with ajax code
JHTML::_('script', 'ajax-file.js', 'media/path/to/js/dir/');
// Create ajax div
$ajaxDiv = '<div id="ajax-div"></div>';
// Modify article text by adding the div for ajax at the top
$article->text = $ajaxDiv . PHP_EOL . $article->text;
return true;
}
Adding external JS to the head of the document.
精彩评论