Loading...
 

ModuleCreationDev

Getting Started With Modules

So, you love tikiwiki and have an idea for a simple addition to the module list?

Modules are a good way to get started on Tiki.

Don't confuse a module with a feature (see for this FeatureCreationDev ).

A module is a box of content that may be displayed in the right or left (sometimes top) columns and generally contains a bit of info, a list or an action.

They are called blocks in other CMS-s.


A module, like the rest of Tiki is made up of two files:

  • A php file in the modules directory
  • A Smarty template in the templates/modules directory

The PHP file

The php file is a simple php file that can be used to assign custom smarty variables to be used in the smarty template that will make up the module display. As an example, open one of the existing module files and take a look.


Example from /tiki/modules/mod-directory_stats.php


<?php
if($feature_directory == 'y'){
  $ranking = $tikilib->dir_stats();
  $smarty->assign('modDirStats',$ranking);
}
?>


The Smarty template

The Smarty template file is used to generate the actual module display. This file is self contained and simple. Once again, take a look at one of the existing modules already in the directory.


Example from /tiki/templates/modules/mod-directory_stats.tpl


{if $feature_directory eq 'y'}
<div class="box">
<div class="box-title">
{tr}Directory Stats{/tr}
</div>
<div class="box-data">
{tr}Sites{/tr}: {$modDirStats.valid}<br/>
{tr}Sites to validate{/tr}: {$modDirStats.invalid}<br/>
{tr}Categories{/tr}: {$modDirStats.categs}<br/>
{tr}Searches{/tr}: {$modDirStats.searches}<br/>
{tr}Visited links{/tr}: {$modDirStats.visits}<br/>
</div>
</div>
{/if}


Naming your files for success

Keep one thing in mind though, the name of the files is important. The filename will start with "mod-" and end with ".php" and ".tpl" respectively. Everything in between will be displayed in the module list in the admin section of tiki.

You've made it

Just go to the Admin menu and select Modules. You will find your new module in the list that can now be assigned to the left or right.

This isn't very hard

As you can see, there is very little to a successfull tikiwiki module. In fact, this is a fairly complex one. MUCH simpler is the google search. In fact modules don't even need to have a php file if they are strictly display only. An example would be the Application Menu itself, which has no php component. In fact, it is just a Smarty template, albeit a complex one.




Feel free to edit this page


Page last modified on Tuesday 01 June 2004 12:11:41 GMT-0000

Upcoming Events

No records to display

Why Register?

Register at tiki.org and you'll be able to use the account at any *.tiki.org site, thanks to the InterTiki feature. A valid email address is required to receive site notifications and occasional newsletters. You can opt out of these items at any time.