User

Rvsjoen/tutorial/Developing a Module/Part 01: Difference between revisions

From Joomla! Documentation

Rvsjoen (talk | contribs)
Rvsjoen (talk | contribs)
No edit summary
Line 1: Line 1:
= Developing a Basic Module =
= Developing a Basic Module =


Let's create a ''Hello World!'' module. All file name and path references in this tutorial are relative to the directory you are developing your extension in.
Let's create a ''Hello World!'' module. All file name and path references in this tutorial are relative to the directory you are developing your extension in. In order to create a very basic module, all that is really needed is two files. A module file and an XML manifest. This module will do nothing more than to spit out the words "Hello World!" into the position in which it is published.
 
In order to create a very basic module, all that is really needed is two files. A module file and an XML manifest.


With your favorite editor, create the following file
With your favorite editor, create the following file
Line 46: Line 44:
</span>
</span>


As we can see, there is a lot of markup here. This is pretty much a minimal extension manifest and we will try to explain the most important bits and pieces.  
As we can see, there is a lot of markup here. This is pretty much a minimal extension manifest and we will try to explain the most important bits and pieces. The important thing to note here is the '''module="mod_helloworld"''' attribute which specifies which file is considered the entry point for the module. In theory this can be any file you want but to follow proper naming conventions we name this file '''mod_helloworld.php'''.


== Installation and Testing ==  
== Installation and Testing ==  


Before testing your shiny new module you have to install it, in Joomla! there are two ways of doing that, either by packaging the extension into an installable zip package or by using the discovery method. Both methods are described below but I recommend using the packaged zip file as a beginner because it is more hostile towards errors especially in the XML manifest.
Before testing your shiny new module you have to install it. In Joomla! there are two ways of doing that, either by packaging the extension into an installable zip package or by using the discovery method. Both methods are described below but I recommend using the packaged zip file as a beginner because it is more hostile towards errors especially in the XML manifest.


=== Installing your component ===
=== Installing your component ===
Line 57: Line 55:
A new feature made available in Joomla! 1.6 is "discover." That means you can place the files in the correct places inside your Joomla! installation, and the "Discover" option within the extension manager will install it, when selected.
A new feature made available in Joomla! 1.6 is "discover." That means you can place the files in the correct places inside your Joomla! installation, and the "Discover" option within the extension manager will install it, when selected.


The proper file path for this module will be in  
The proper file path for this module will be in '''modules/mod_helloworld''' within the Joomla! root.
 
After installation will notice that the Hello World component is visible in the administrator site of your Joomla! installation under the Components menu.


=== Packaging an installation zip file ===
=== Packaging an installation zip file ===
Line 71: Line 67:
If you want to test this module, you first need to do a couple of things.
If you want to test this module, you first need to do a couple of things.


# Go to the Module manager and edit the module
# Go to the Module Manager and edit the module
# Assign the module to a module position
# Make sure the module is published
# Make sure the module is published
# Assign the module to a module position
# Make sure the module is assigned to show on some pages in the module assignment dialog
# Make sure the module is assigned to show on some pages in the module assignment dialog


After performing these steps you can navigate to the frontend and view the module.
After performing these steps and saving the module you can navigate to the frontend and view the module.


== File listing ==  
== File listing ==  

Revision as of 16:49, 13 March 2012

Developing a Basic Module

Let's create a Hello World! module. All file name and path references in this tutorial are relative to the directory you are developing your extension in. In order to create a very basic module, all that is really needed is two files. A module file and an XML manifest. This module will do nothing more than to spit out the words "Hello World!" into the position in which it is published.

With your favorite editor, create the following file

mod_helloworld.php

Hello World!

With your favorite editor, create the following file

mod_helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" method="upgrade">

        <name>Hello World!</name>
        <!-- The following elements are optional and free of formatting constraints -->
        <creationDate>Once upon a time</creationDate>
        <author>John Doe</author>
        <authorEmail>john.doe@example.org</authorEmail>
        <authorUrl>http://www.example.org</authorUrl>
        <copyright>Copyright Info</copyright>
        <license>License Info</license>
        <!--  The version string is stored in the extension table -->
        <version>0.0.1</version>
        <!-- The description is optional and defaults to the name -->
        <description>Description of the Hello World module ...</description>

        <!-- Note the folder attribute: This attribute describes what to copy
                into the module folder -->
        <files>
                <filename module="mod_helloworld">mod_helloworld.php</filename>
                <filename>mod_helloworld.xml</filename>
        </files>

</extension>

As we can see, there is a lot of markup here. This is pretty much a minimal extension manifest and we will try to explain the most important bits and pieces. The important thing to note here is the module="mod_helloworld" attribute which specifies which file is considered the entry point for the module. In theory this can be any file you want but to follow proper naming conventions we name this file mod_helloworld.php.

Installation and Testing

Before testing your shiny new module you have to install it. In Joomla! there are two ways of doing that, either by packaging the extension into an installable zip package or by using the discovery method. Both methods are described below but I recommend using the packaged zip file as a beginner because it is more hostile towards errors especially in the XML manifest.

Installing your component

If you have used Joomla before reading this tutorial, you have noticed that extensions are installed using a compressed file containing all the things which are needed for installing and uninstalling them.

A new feature made available in Joomla! 1.6 is "discover." That means you can place the files in the correct places inside your Joomla! installation, and the "Discover" option within the extension manager will install it, when selected.

The proper file path for this module will be in modules/mod_helloworld within the Joomla! root.

Packaging an installation zip file

Create a compressed file of your extension directory using the structure shown in the file listing section of this page or download the provided installable package.

When you have this package, install it using the extension manager.

Testing your module

If you want to test this module, you first need to do a couple of things.

  1. Go to the Module Manager and edit the module
  2. Assign the module to a module position
  3. Make sure the module is published
  4. Make sure the module is assigned to show on some pages in the module assignment dialog

After performing these steps and saving the module you can navigate to the frontend and view the module.

File listing

Download this part

To be continued...

Articles in this series

This tutorial is supported by the following versions of Joomla!

Joomla 2.5