The Template
We have created the backend of our module and the next thing we need to do is create the frontend for this module.
We will start from the frontend template file located at /modules/HelloWorld/template/index.tpl :
<h1>{$QoolMO->modLang.QUOTE_OF_DAY}</h1>
<p>{$QoolMO->quote}</p>
It really is that simple.
We print a message in <h1> tags and we create a paragraph with our quote in it. We are done.
The Module file
Next we have to do is create the frontend code. This is the skeleton we must use:
<?php
class
quotes{
var
$QoolDB = array();
var
$QoolRS = array();
var
$QoolUR = array();
var
$QoolSL = array();
var
$QoolUI = array();
var
$site = array();
var
$QoolTR = array();
var
$QoolSP = array();
var
$QoolSE = array();
var
$QoolFS = array();
var
$QoolQM = array();
var
$QoolWF = array();
var
$QoolPM = array();
var
$QoolQC = array();
var
$QoolLS = array();
var
$QoolFM = array();
var
$QoolDS = array();
var
$QoolVS = array();
var
$QoolQR = array();
var
$modLang = array();
var
$quote = '';
var
$modMenu = array();
function
quotes($search='',$DB,$RS,$UR,$SL,$UI,$site,$TR,$SP,$SE,$FS,$FM,$DS,$VS,$QM ,$QC,$WF,$PM,$LS,$QR){
$this->QoolDB
= $DB;
$this->QoolRS
= $RS;
$this->QoolUR
= $UR;
$this->QoolSL
= $SL;
$this->QoolPM
= $PM;
$this->QoolQC
= $QC;
$this->site
= $site;
$this->QoolQM
= $QM;
$this->QoolWF
= $WF;
$this->QoolLS
= $LS;
$this->QoolTR
= $TR;
$this->QoolQR
= $QR;
$this->QoolSP
= $SP;
$this->QoolSE
= $SE;
$this->QoolFS
= $FS;
$this->QoolFM
= $FM;
$this->QoolDS
= $DS;
$this->QoolVS
= $VS;
//We
include any files needed. Like the language file of the
module
include
$this->site."modules/HelloWorld/languages/ $SL->currentLang/index.lng";
$this->modLang
=
$_LANGUAGE;
if($search!=''){
}else{
}
$this->getRandomQuote();
$this->stopModule();
}
function
stopModule(){
unset($this->QoolDB);
unset($this->QoolRS);
unset($this->QoolSL);
unset($this->QoolUI);
unset($this->QoolUR);
unset($this->site);
unset($this->QoolSP);
unset($this->QoolFS);
unset($this->QoolVS);
unset($this->QoolRB);
unset($this->QoolTR);
unset($this->QoolSE);
unset($this->QoolFM);
unset($this->QoolQM);
unset($this->QoolWF);
unset($this->QoolQC);
unset($this->QoolPM);
unset($this->QoolLS);
unset($this->QoolQR);
}
}
?>
The code above is nearly the same as the one we used in the backend. There are some things you have to notice. For example the class name is quotes. We have set this in the install.ini file when we started creating our module. One more difference is the $search check:
if($search!=''){
}else{
}
This code checks if the core is searching something and if our module supported search it would handle the search. We also added this line of code:
$this->getRandomQuote();
which will get a random quote and assign it to Smarty in order to display it with our template. This is the code of our method:
function getRandomQuote(){
$DB =
$this->QoolDB;
$RS
= $this->QoolRS;
$site
= $this->site;
$table
= $RS->db_prefix.$this->site."_"."helloworld";
$sql
= "SELECT * FROM `$table` WHERE
`in_trash`=?";
$data =
array(0);
$query =
$DB->query($sql,$data);
if
(PEAR::isError($query))
{
$this->quote =
null;
}else{
while
($rows =
$query->fetchRow(DB_FETCHMODE_ASSOC)){
$quotes
= $rows;
}
$this->quote
= $quotes;
}
}
Our module is now ready. All we have to do is enable it from the admin panel:

The magenta colored arrows show what we need to change to activate our module. Now save it, add some more quotes, insert the QUOTE_OF_DAY string into the language file of your module and load your site:

Our sample module is ready. The module has been added to the main menu and it displays a random quote each time reloaded.












