Documentation

Modules

Overview

Modules are extensions which present certain pieces of information on your site. It's a way of presenting information that is already present. This can add a new function to an application which was already part of your website. Think about latest article modules, login module, a menu, etc. Typically you'll have a number of modules on each web page. The difference between a module and a module is not always very clear for everybody. A module doesn't make sense as a standalone application, it will just present information or add a function to an existing application. Take a newsletter for instance. A newsletter is a module. You can have a website which is used as a newsletter only. That makes perfectly sense. Although a newsletter module probably will have a subscription page integrated, you might want to add a subscription module on a sidebar on every page of your website. You can put this subscribe module anywhere on your site.

Another commonly used module would be a search box you wish to be present throughout your site. This is a small piece of re-usable HTML that can be placed anywhere you like and in different locations on a template-by-template basis. This allows one site to have the module in the top left of their template, for instance, and another site to have it in the right side-bar.

Directory Structure & Files

The directory structure used allows you to separate different MVC applications into self-contained units. This helps keep related code organized, easy to find, and can make redistribution as packages considerably easier. To illustrate the typical module directory structure and files:

/hubzero
  /modules
    /mod_{ModuleName}
      /tmpl
        default.php
      helper.php
      mod_{ModuleName}.php
      mod_{ModuleName}.xml

A Joomla! 1.5 Module is in its most basic form two files: an XML configuration file and a PHP controller file. Typically, however, a module will also include a view file which contains the HTML and presentation aspects.

/tmpl
This directory contains template files.
default.php
This is the module template. This file will take the data collected by mod_{ModuleName}.php and generate the HTML to be displayed on the page.
helper.php
This file contains the helper class which is used to do the actual work in retrieving the information to be displayed in the module (usually from the database or some other source).
mod_{ModuleName}.php
This file is the main entry point for the module. It will perform any necessary initialization routines, call helper routines to collect any necessary data, and include the template which will display the module output.
mod_{ModuleName}.xml
The XML configuration file contains general information about the module (as will be displayed in the Module Manager in the Joomla! administration interface), as well as module parameters which may be supplied to fine tune the appearance / functionality of the module.

While there is no restriction on the name itself, all modules must be prefixed with "mod_".

Examples

A simple "Hello, World" module:

Download: Hello World module (.zip)

A module demonstrating database access and language file:

Download: List Names module (.zip)

Last modified: