How to create a simple joomla plugin?

I am having a real problem, which is probably very easy to create and use joomla plugins.

Here is what I have done so far.

I created a sample joomla plugin using the following two files inside a folder and named them the same.

I have listed their contents below.

The plugin is installed correctly through the admin panel

I then enable it through the plugin manager

OK. everything is ready to go.

How to use the plugin in the article after turning on 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.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> 
+5
source share
1 answer

The plugin should not have echoing or printinformation.

, , . var_dump .

Joomla Content Plug-in.


3/17/2011

. , &$article. . :

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;
}

JS .

+5

All Articles