First Module - Part I

  • PDF

For our first module we'll write a 'Hello World' module.  This will involve writing a descriptor file (the XML based file called templateDetails.xml is a Template descriptor file) and the module code file.  The code file will be called mod_helloworld.php.

Here is the sample descriptor file, mod_jhmhelloworld.xml:

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="upgrade">
 <name>Hello World</name>
 <description>Hello World Module</description>
 <filename module="mod_jhmhelloworld">mod_jhmhelloworld.php</filename>

and here is the sample code for mod_jhmhelloworld.php:

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
echo JText::_( 'Hello World!');

The XML file and PHP file will be in the same directory - mod_jhmhelloworld and zipped up to install the module.

The updates from Joomla 1.5 to a Joomla 1.6, 1.7, 2.5 module include the following changes:

<install type="module" version="1.5.0">

has been changed to: 

<extension type="module" version="2.5.0" client="site" method="upgrade">
You will also need to change the closing tag </install> to </extension>

If your module is not shown after you install - check the following items in the administrator:
  • Is it published?
  • Does it have a valid position for your default template?
  • Is the module assigned for the pages you are viewing?

This was based on code is from the book, Professional Joomla!, by Dan Rahmel.