Using the Templating system is pretty simple. Unpack the zip file somewhere, include it in your script, and call the static "process" method:
Template::process(templateName, optional variables,
optional return);
The variables array contains everything that you want to be accessible as a variable to the templates. There are a few variables in this, however, that have special meaning to the template software itself.
LOGIN_REQUIRED,
the template will look for a valid login status and if it is not
found, will instead load the "login" template. This new template
will also have access to a $templateURL variable
which contains the original URL that was loaded. Basically, you
use this to force someone to be logged in before the actual
template will load, and give you the opportunity to tell the login
process where the user originally tried to access.
true, the templates
to be processed before the main content will not be included in
the final output.
true, the templates to be processed after the main
content will not be included in the final output.
The template files themselves are just regular php files, without
a .php extension, though if you wanted the templates to be named
templatename.php, you could do so, you'd just have to send
the complete filename. To prevent shifty template designers from
mucking about with your code, actually the actual processing of a
template file is done inside a closure where the only variables that
can be accessed are the ones that you provide in the
variables array. The template instance itself is always
available to the processing template as $t, and provides
the following functions that the template will need:
$t->processFile(string filename)$t->processFile("navigation"). The new template will
have access to all of the variables that the calling template has.
$t->vars(string variablename)null
$t->addError(string errormessage)div#templateErrorMessage. Each individual message
will be wrapped in a span.templateError tag and
separated by <br /> tags.
Configuring is pretty easy. Wherever the Template.php file is located, the program will look for a templates/ directory which should house the templates that will be directly processed. Inside that should be a globals/ directory, which will house, naturally, the global template files. Examples of these are in the download.
You'll want to set the following things inside the Template.php file itself:
$beforeContent should be an array of the global
templates that you want run before the main template file, in the
order that you want them run.
$afterContent should be an array of the global
templates that you want run after the main template file, in the
order that you want them run.
loginFound() is just a stub currently. You should
replace it with whatever you need to check to see if there is a
current, valid login and have it return true/
false if you want to use the
LOGIN_REQUIRED const.