Filmmaker, Video Editor, Motion Graphics Designer, and Photographer in Cairo, Egypt.
Keeping notes to remember.. You may consider it some sort of Documentation.

Stay In Touch

Wednesday, April 14, 2010

Developing Joomla 1.5 Module:: Hello World!



Never thought of developing your own Joomla module??.. I did :D
Here's a simple steps for developing a simple module that says "Hello World".

Prerequisites:
# At this stage, being familiar with Joomla, PHP, XML, and HTML is needed.

System Requirements:
# Having a Joomal site installed is needed.

Developing Steps:

Step 1: Module Files Structure
- Create a folder/directory with name "mod_helloworld".
- There are two basic files that are used in the standard pattern of module development:
# mod_helloworld.php: This file is the main entry point for the module.
# mod_helloworld.xml: This file contains information about the module. It defines the files that need to be installed by the Joomla! installer and specifies configuration parameters for the module.
- Create those two files in your module's folder/directory.
Hint: the folder and those two files has to have the same name, and has to start with "mod_".

Step 2: The PHP File
For now, we need only one line on PHP code, and a HTML tag for printing the text. So, our PHP file will be as follows:

<?php

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

<h1>
Here we are!</h1>

<p>It workssssssssss!!!</p>

The PHP line is commonly found at the start of Joomla! PHP files. "_JEXEC" is a constant with a boolean value either being 1 or 0. This constant is used to check if Joomla! is calling the file, or if a person has directly typed the path to the file in the URL. Joomla! sets _JEXEC to 1 (or any positive value really) when it is the one calling the file. _JEXEC is normally used to check to make sure that no direct access to the file is being used.


Step 3: The XML File
Here's how the module XML file has to look like:


# install: This is the parent tag that defines the rest of the installer file for Joomla!. It has an attribute for type which in this case is module. It also takes a value for the version of Joomla! it can run on.
# name: This is the name of your module.
# author: This is the name of the author for the module.
# creationDate: This is the date the module was created.
# copyright: This is the copyright holder of the module's code.
# license: This is the name of, or a reference to, the license under which the module is released.
# version: This is the version of the module.
# description: This is a free text description of the module.
# files: This is a collection of the files included with the module.
# filename: This is a file that is used by the module. Any number of files can be listed, including files in a subdirectory.
# param: This element takes a number of mandatory and optional arguments that depend on the type argument.
# type: This specifies the type of HTML form control used in the Template Parameters screen in the Administrator to allow the user to change the value of the parameter.
# name: This is the unique name of the parameter.
# default: This is the default value of the parameter.
# description: This is text that will be displayed as a tooltip for the field in the Template Parameters screen in the Administrator.
# label: This is the descriptive title of the field which will be shown to the user in the Template Parameters screen in the Administrator.

The Template Parameters screen for this example will look like this:


Step 4: Installation
- Now zip your module's folder.
- Install it as you used to install any Joomal module.
- Make sure that it's enabled.


- Then click Preview to check out what you did


Pretty cool!


References:

http://help.joomla.org/content/view/775/125/
http://docs.joomla.org/Tutorial:Creating_a_Hello_World_Module_for_Joomla_1.5
http://www.evontech.com/login/topic/542.html
http://docs.joomla.org/Defining_a_parameter_in_templateDetails.xml