Welcome to the navigation

Anim proident, exercitation quis ut ex amet, ad aute irure in dolor occaecat culpa non adipisicing esse pariatur, ut laborum, incididunt minim elit, eu consectetur. Est laboris ut nulla amet, consequat, aliquip culpa mollit cillum laborum, labore lorem excepteur ex aute sed id dolor ea pariatur, incididunt sint in magna

Yeah, this will be replaced... But please enjoy the search!

Joomla! 1.7 Hello World Module Evolved

Categories Tags

So you want to write some modules for Joomla! 1.7 I suppose. Well the good news is that this is a part of Joomla that still simple to work with. I've made this mod_helloworld a bit more complex than the example presented on other sites since I introduce one of the most useful elements in Joomla, the parameters as well as view selection.

Update: The file is available for download once again, http://cdn.herlitz.nu/blog/mod_helloworld_1_7.zip

Whats in it?

Some files...

You can set this up in the admin interface

And this will be displayed

Code

helper.php

<?php
/**
 * Helper class for Hello World 1.7 skeleton module
 * @author Trikks, 
 */
class modHelloWorldHelper {

    /** 
 * Retrieves the hello message * 
 * @param array $params An object containing the module parameters 
 * @access public 
 */
    function getHello($params) {
        return 'Hello World!';
    }

}
?>

mod_helloworld.php

<?php
/** 
* Entry Point for Hello World 1.7 skeleton module 
* @author Trikks,  
*/
defined( '_JEXEC' ) or die( 'Restricted access' ); // no direct access allowed

// Include the syndicate functions only once
require_once dirname(__FILE__).DS.'helper.php'; // get helper files

$hello = modHelloWorldHelper::getHello($params);
require JModuleHelper::getLayoutPath('mod_helloworld', $params->get('layout', 'default'));
?>

mod_helloworld.xml

The settings file, note the parameters in the config section. These parameters are the ones showing in the backend. You fetch them in the views by typing

$params->get('param_name')
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="1.7" client="site" method="upgrade">
    <name>mod_helloworld</name>
    <author>Joomla! Project</author>
    <creationDate>October 2011</creationDate>
    <copyright>Copyleft</copyright>
    <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
    <authorUrl></authorUrl>
    <version>1.7.0</version>
    <description>Trikks simple hello world module.</description>
    <files>
        <filename module="mod_helloworld">mod_helloworld.php</filename>
        <filename>mod_helloworld.xml</filename>
        <filename>index.html</filename>
        <filename>helper.php</filename>
        <filename>tmpl/default.php</filename>
        <filename>tmpl/index.html</filename>
    </files>
    <config>
        <fields name="params">
            <fieldset name="basic">
                <field name="mod_helloworld_text" type="text" label="A textfield" description="Enter any text"/>
                <field name="mod_helloworld_list" type="list" label="A dropdown" description="Use for custom dropdowns" default="1">
                    <option value="1">JYes</option>
                    <option value="0">JNo</option>
                </field>
                <field name="mod_helloworld_radio" type="radio" label="Radiobuttons" description="Use radiobuttons for explicit selections" default="1">
                    <option value="0">JNo</option>
                    <option value="1">JYes</option>
                </field>
                <field name="layout" type="modulelayout" label="JFIELD_ALT_LAYOUT_LABEL" description="JFIELD_ALT_MODULE_LAYOUT_DESC"/>
                <field name="mod_helloworld_image" type="media" label="Mediaselector" description="Select media"/>
            </fieldset>
        </fields>
    </config>
</extension>

tmpl/default.php

The default view of this module

<?php
// This is the default output file
defined('_JEXEC') or die;

// Echo from getHello method
echo "<p style='font-weight: bold;'>$hello</p>";

// Echo params
echo "<p>";
echo $params->get('mod_helloworld_text') . " | ";
echo $params->get('mod_helloworld_list') . " | ";
echo $params->get('mod_helloworld_radio') . " | ";
echo $params->get('mod_helloworld_image');
echo "</p>";
?>

tmpl/notdefault.php

Simply an additional view which will render a different result in the frontend

<?php
// This is an optional output file
defined('_JEXEC') or die;

// Echo from getHello method
echo "<p style='font-weight: bold;'>$hello</p>";
echo "<p style='font-style: italic;'>- O Hai!</p>";

// Echo params
echo "<p>";
echo $params->get('mod_helloworld_text') . " | ";
echo $params->get('mod_helloworld_list') . " | ";
echo $params->get('mod_helloworld_radio') . " | ";
echo $params->get('mod_helloworld_image');
echo "</p>";
?>