Main menu
WalkswithMeJoomlaJoomla plugin development tutorial

Joomla plugin development tutorial

Joomla plugins are most powerful extension type in Joomla CMS while rendering the content the out put can alter with Joomla plugin or you can just insert few codes inside form or any place you want. Joomla plugin offers more features to Joomla CMS.

Joomla CMS have different plugin type ,

1. Authentication
2. Captcha
3. Content
4. Editors
5. Extensions
6. Finder
7. Quick Icons
8. System
9. User

Based on above plugin type the events will change. The events are the functions name that can help you to catch up the proper function on the situations.

Here I will explain one of the above plugin type content my Joomla plugin development tutorial will help you to create a sample short code plugin. These days WordPress is comes with powerful shotcode options , the same feature is also available in Joomla we have to create the proper plugin type and choose the correct event type for the plugin development.

In Content plugin onContentPrepare() is one of the event used to alter the article content while rendering the content. There are many other events are available for Joomla content plugin.


onContentPrepare($context, &$article, &$params, $page = 0)

the second parameter of this function will retrieve the complete article object of the current viewing article. you will get the article text by using


$article->text;

The demo plugin just convert some sample short codes to its proper elements, like button , links ,textboxes etc. Its just a demonstration for the short code content plugin.Keep in mind content plugin will render only the content (articles ) not any other components or 3rd party extension will not work with these events. If you are looking for some short codes that work with all component then try with System Plugin Creation.

The content plugin code will be look like,


defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgContentShortcode extends JPlugin{
function plgContentShortcode( &$subject, $params ){
parent::__construct( $subject, $params );
}
public function onContentPrepare($context, &$article, &$params, $page = 0){
global $mainframe;
$articleText       =    $this->CheckShortCodes($article->text);
$article->text     =     $articleText;
}
public function CheckShortCodes($article_content){
$catFound    =    array();
$pattern    =     '/\[([A-Za-z_-]+)\]/';
preg_match($pattern, $article_content, $catFound);
$content    =    preg_replace($pattern, $this->CheckingShortCodesToReplace($catFound[1]), $article_content,1);
if(sizeof($catFound) > 0)
$content = $this->CheckShortCodes($content);
return $content;
}
function CheckingShortCodesToReplace($cat_name){
switch($cat_name){
case 'button' :
return '<button name="button" >I am a Buttom</button>' ;
break;
case 'link' :
return '<a href="www.walkswithme.net" >I am a link</a>' ;
break;
case 'textbox' :
return '<input name="textbox" value="I am a text box" />' ;
break;
case 'textarea' :
return '<textarea name="text" >I am a text area</textarea>' ;
break;
}
}

In the editor you can use it like

Joomla Content plugin development

Joomla Content plugin development

In the front end article section it will render like,

Joomla plugin development

Joomla plugin development

You can just download a working sample of this Content plugin, Its just a demo you can get the basic idea of Joomla Content plugin from this sample plugin. also I hope  this article will help you to create some powerful short code plugin for Joomla users :):):)

Download527 downloads

3 thoughts on “Joomla plugin development tutorial

    1. This tutorial is aimed for Joomla Plugin development, also in the example I was used content events.
      So it basically work with com_content or artcile pages.

      If you need to work with module or any other compoents out put to alter with plugin you have to use System plugin group and onrenderAfter or oncontentPrepare events.

      Hope it make sense.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
FacebookTwitterGoogle+RSS