The PEAR ITX Templating System - Adding ITX to your PHP script
(Page 3 of 5 )
First of all, ITX is a part of the PEAR project. While you do not need to have the complete set of PEAR files accompanying your script, you will most likely want to distribute the ITX source with your script. I've only worked with a scarce few web hosting companies that have PEAR classes preinstalled for their clients.
ITX is object-oriented like all PEAR code. Don't worry though. Even if you can't get a grip on OOP, there are only a few tricks you need to learn to use it properly and effectively in your applications!
What do you need?
Assuming you have already configured your PHP and added PEAR's directory into your include path, it's a very simple process to put ITX into your application:
<?php include("HTML/ITX.php"); ?>
Basics of the templating system
To initialize the templating system, we need to make an instance of the IntegratedTemplateExtension class:
<?php $tpl = new IntegratedTemplateExtension("/template/location/"); ?>
From now on, every time we mention the $tpl variable, we are talking about this instance of the IntegratedTemplateExtension class.
The ITX constructor takes one parameter. This parameter (with the value "/template/location/" in the example) is the directory from which templates will be loaded.
In order to process data from a template, we need to instruct ITX to load that template. Here is how we do it:
This will load the file named school-grades.tpl into the instance of ITX, and will enable you to start processing your template. Beware, though, that this method does not report errors. No error will be reported, and no template will be loaded if you use a non-existent file name. Your script will just die in silence without an easy diagnostic method.