Zippy WiFi Blog
News, About Us, Tech Trends, Recent Deployments
One company - One Connection at a time - with a vision of tomorrow.
There IS an alternative to connectivity and mobility. Join our group to help your neighborhood carrier-class network grow faster!

Joomla! - the difference between modules and components

Print the article

This entry was posted on 4/9/2006 6:30 PM and is filed under Web Development and Design.

originally posted at http://www.jlleblanc.com/index.php?option=com_content&task=view&id=11&Itemid=52

Components vs. Modules PDF Print E-mail
Please note: although the described use of parameters and module positions here are specific to Mambo 4.5, the concepts behind self-contained templates, modules, and components still apply for newer versions. -Joseph L. LeBlanc, 11/3/04

Quite often throughout the message boards on forums.opensourcematters.org, new Joomla users display confusion over modules and components. However, once this differentiation is made, the architecture of Joomla becomes very clear. So, what is the difference between a component and a module?

 

Here's the short answer: Modules can appear on any page and are usually very simple. Components load as their own page and can be quite complex.

 

This should be a satisfying answer if you are simply curious or don't have a lot of time to read about the wonders of the Joomla architecture. For those interested in more, there is quite a bit to discover. Let's start with the way a Joomla page actually loads…

 

When somebody visits your site, the index.php file is called from the root directory. This file loads many different classes and other pieces of code that make Joomla work. After all of this code loads, Joomla looks for the directory of the current template and attempts to load the index.php file located there. So, both the root directory and the template directory have their own index.php file, with the root index loading the template index for the layout.

 

The index.php file in the template directory looks mostly like a typical HTML file. Within this file, you should find the code <?php include_once('mainbody.php'); ?>. This tells PHP to stop writing lines of HTML and include the code from mainbody.php, which loads exactly one component. This means that every page in Joomla loads a component. (OK, well, you could remove the include for mainbody.php and no components would ever load, but this would severely limit the functionality of your site.) By default, Joomla will load the component corresponding to the first item in the menu. Typically this is the 'Home' item which points to the 'frontpage' component. Frontpage displays the introductions to news articles written by site authors. When you click to on a link for an article, it tells Mambo to load the 'content' component, along with the specific article to load from the database. Other links can tell Joomla to load other components.

 

In addition to including mainbody.php, the template will have many mosLoadModules() function calls, ie… mosLoadModules('left');. This code tells Joomla to load all of the modules in the 'left' position that are attached to the current component (default positions are left, right, top, bottom, inset, user1, and user2). When a module is configured in the backend, a selection list appears allowing the administrator to attach the module to certain components (or all of them, which is very typically the case). This allows the administrator to set, say, the login form on the front page, but not on subsequent pages. Templates are not required to load the modules for all the positions (or any at all!), but it is typically helpful to load at least one module so that there is a place for the menu, unless you wish to code your own navigation.

 

When visitors load your site, they probably won't know or care about the difference between modules and components. However, anyone using the administrator interface to modify the site will want to learn how to manage these elements. Modules can be installed from the install/uninstall option under the modules menu. This will provide a list of the modules installed from files, with a form for uploading more modules at the bottom.

 

When the 'Manage Modules' option is clicked on the menu, another list is presented with options for publishing/unpublishing, positioning, and ordering. This list may be longer than the first list, as custom content modules can be created. These modules are not fed from code in the modules folder, but are fed from content in the database as articles are. They appear just as other modules would.

 

All modules allow for the inclusion of parameters. Parameters allow module developers to give site administrators a way of changing the module's options without creating a complex interface. For instance, if a module developer wanted to give administrators control over the background color, a parameter could be defined in the module management. Administrators would click on the title of this module, then type backgroundcolor = green (or whichever color desired) on a single line in the 'Parameters' box.

 

Designing component administration requires much more effort, but results in easy to use interfaces that allow administrators to manage complex functionality. When a component's administrative interface is loaded, the file admin.[nameofthecomponent].php is executed from the /administrator/components/com_[nameofthecomponent] folder. This file then loads the appropriate interface for the current task or action. More about creating administrative interfaces can be discovered through the Daily Message Component Tutorial.

 

Once you understand the difference between components and modules, the general structure of Joomla as a whole becomes very clear. If you are comfortable with your PHP programming skills, you should not hesitate in creating your own components and modules. However, it is advisable to check mosforge.net first to search for open-source solutions already under development. Chances are that somebody has created the functionality you desire, or has released something very similar.

 



 

What did you think of this article?




Trackbacks
Trackback specific URL for this entry
  • No trackbacks exist for this entry.
Comments
    • No comments exist for this entry.
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.