Templates rule, well they are very very useful and they are very useful.

The first thing you are going to want is a template class from phplib. Get it here http://phplib.netuse.de/

Don't be worried about all the files, you hardly need any, in fact I would recommend that all you need are db_mysql.php and templates.php

Now... there is lots of information in this forum on how to use both of these classes, so what can I add?

Well, i wanted to do something a bit different. I am going to have quite a lot of templates and I want to store them in a database (because it makes updating them a LOT easier that way).

Now using phplib as it currently is, getting 10 templates for 1 page take a lot of effort. There must be a better way, and well i found one.

NOTE: I can't gurantee this will work for you or be the best way to do it etc.. but it works for me!

You need a table, i called mine templates (funny that) and you need a column for the templates name and then a column for the template.

Now you need these two extra functions:

PHP Code:
// gets an array of templates from the database
function template_get($template) {
$query "SELECT * from templates WHERE name in ($template)";
$db->next_record()) {
$tmp[$db->f(name)] = $db->f(template);

// sorts out an array of templates before going to function above
function array_sort($array) {
$array as $key => $val) {
$tmp .= "'$val',";
$tmp substr($tmp,0,-1);

The 2nd function here just sorts out an array of templates ready for a sql call. The first function then gets all the templates from the database.

Now.. all you need to do on a page where you want to load up a few templates is;

PHP Code:
that "loads" the three templates new_registration, admin_new_registration and validate_new_registration from the database. Now when ever you want to use them all you have to do is:

PHP Code:
sort of thing. If you have any more variables you want included in templates then a few extra lines like:

PHP Code:
// add validate_number as template
"validate_number" => "$validate_number"
is again all you need.

This saves masses of typing if you want to pull lots of templates from a database.

I also made a small system to get a lot of settings from a database so that they can be used inside templates. If you want this as well just ask.

Hope that helps someone, it has me and a big thanks to all those php helpers out here, especially that feline helper, for.. well their help!