A tab module appears along with Thyme's other tabs (Day, Week, Month etc..). In this example, we'll create a module that just displays the text Hello World and appears as a tab.
To start, as with any module in Thyme, create a sub-folder under the modules folder. This should be unique to any other module. We'll call ours hello_world.
Every module that wants to interact with Thyme must have a register_module.php file that tells Thyme about it. So let's open up modules/hello_world/register_module.php in your favorite editor. register_module.php simply adds itself to the global array $_cal_modules.
Since our module is called hello world, and we want the tab's title to be Hello World, we'll set the display_name property:
$_cal_modules['hello_world']['display_name'] = "Hello World";
Great. Now Thyme knows about our module, it just doesn't know what to do with it. We'll tell Thyme that we want our module to be a tab by setting the parents property by adding the line:
$_cal_modules['hello_world']['parents'] = array("tab");

Ok, now Thyme knows to display this module as a tab, but we're not quite happy with the placement. Let's place it as the last tab by setting it's priority to a higher value.
$_cal_modules['hello_world']['priority'] = 100;
The highest priority is the priority with the lowest value. This may cause some confusion. It may help to think of priority as position from left to right. A higher position will move the tab further to the right.
So now Thyme knows about the module and where exactly to display it, now we have to tell it what to do when this module is active. To do this, use the include property:
$_cal_modules['hello_world']['include'] = 'hello_world/hello_world.php';
This is the file to include when the module is active as relative to the modules directory.
Our register_module.php file should now look like this:
<?php
$_cal_modules['hello_world']['display_name'] = 'Hello World'; $_cal_modules['hello_world']['parents'] = array('tab'); $_cal_modules['hello_world']['priority'] = 100; $_cal_modules['hello_world']['include'] = 'hello_world/hello_world.php';
?>
So now we'll have to create the file hello_world.php. Open up hello_world.php in your favorite text editor. In this file, we'll just add the text Hello World!.
<h3 align='center'>Hello World!</h3>
The result when clicking on the Hello World tab is displayed below:

Note that if you want forms and links to stay within your module, they must include your module's name as a $_REQUEST variable ($_GET, $_POST, or $_COOKIES). This can be done in a link by setting '?module=hello_world' or in a form by using a hidden field <input type=hidden name='module' value='hello_world'>.
Though our example simply displays an html message, we could have used PHP code in our hello_world.php file. The applications are endless. Create a new application embedded into Thyme or include() an existing one. Create a message of the day, address book, or use iframes to embed a web page.
|