Version 5, last updated by JohnBell at 23 Mar 22:16 UTC
Creating a module
NOTICE: This specific example will only work under Nooku Server
1. Introduction
Modules are a fast way to show small bit of content. Ideal for stuffing on your frontpage to enhance the UX.
2. Basic files
For this tutorial we are making a module which is gonna show the 5 most recent added articles.
We need the following files:
/modules/mod_latestarticles/html.php
/modules/mod_latestarticles/mod_latestarticles.php
/modules/mod_latestarticles/tmpl/default.php
/modules/mod_latestarticles/mod_latestarticles.xml
2.1 mod_latestarticles.php
<?php
//Starts up the module
echo KService::get('mod://site/latestarticles.html')
->module($module)
->attribs($attribs)
->display();2.2 html.php
<?php
//Class which assigns data to the view.
class ModLatestarticlesHtml extends ModDefaultHtml
{
public function display()
{
//Fetches the latest 5 articles, which are published, and sorts them by date.
$articles = $this->getService('com://admin/articles.model.articles')->limit(5)->state(1)->sort('created_on')->direction('DESC')->getList();
//Assign the variable to the view.
$this->assign('articles', $articles);
//Display the result.
return parent::display();
}
}2.3 default.php
<? //Shows the results and creates links to the specific article. ?>
<ul>
<? foreach($articles as $article) : ?>
<li><a href="<?= @route('option=com_content&view=article&id='.$article->id); ?>"><?= $article->title; ?></a></li>
<? endforeach; ?>
</ul>2.4 mod_latestarticles.xml
This is a standard Joomla 1.5 module xml file
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
<!-- Name of the Module -->
<name>Latest Articles</name>
<!-- Name of the Author -->
<author>A Developer</author>
<!-- Version Date of the Module -->
<creationDate>2012-01-23</creationDate>
<!-- Copyright information -->
<copyright>All rights reserved by A.Developer 2012.</copyright>
<!-- License Information -->
<license>GPL 2.0</license>
<!-- Author's email address -->
<authorEmail>info@example.com</authorEmail>
<!-- Author's website -->
<authorUrl>www.example.com</authorUrl>
<!-- Module version number -->
<version>1.0.0</version>
<!-- Description of what the module does -->
<description>Provides a basic "latest articles" list</description>
<!-- Listing of all files that should be installed for the module to function -->
<files>
<!-- The "module" attribute signifies that this is the main controller file -->
<filename module="mod_latestarticles">mod_latestarticles.php</filename>
<filename>html.php</filename>
</files>
<!-- Optional parameters -->
<params />
</install>3. Finished!
Congratulations you have created your first module in Nooku.
To get it running you'll need to add the module in Administrator > Extensions > Modules