Page 1 of 6
Joomla! Modules are probably one of the most important types of extensions for a Joomla! CMS installation. Sure, plugins are nice, but modules actually display something on your website, and they're flexible enough to go just about anywhere. There are lots of modules available all over the web to do all sorts of things, and many of those are free. But what if you want a module to do something on your site and you can't find an existing Joomla! extension that will do it the way you want, or what if you're like me, and you just like doing things yourself, figuring stuff out and just generally getting your hands dirty. Well, don't worry, creating your own Joomla! Module is pretty easy, and this tutorial will guide you through the basics.
To create a Joomla! Module, all you really need are a few files in a .ZIP package. This will be accomplished by creating four files:
- helper.php - the helper file for the module
- mod_[module_name].php - the php file that runs the module
- mod_[module_name].xml - the xml file that tells Joomla! the details of your module
- tmpl\default.php - the template file for your module (located in a folder called 'tmpl')
Technically, you could get this done without needed the helper or template file, but that will severly limit your code, and including those files is a standard coding practice for Joomla!, so if you want to list your module in the Joomla! Extensions Directory, then you will need to include them.
There are several different "Hello World!" tutorials out there for Joomla! Modules, so for this tutorial, we'll be going a little farther. For the purposes of this discussion, we're going to break apart dcPagesApps PayPal Donate Module. This module is fairly simple, but includes some user-defined parameters so that we can walk through how to set that up as well. This module works by doing the following:
- Get parameter values
- Check parameter values and update if necessary
- Pass that info to the template
It's really very easy so let's dive in.