> This has been some great info. I appreciate it. Can someone explain what
> the purpose of a template engine is and possibly draw up a simple diagram
> of how one might work as it relates to DB-related projects?

Obviously the main purpose of a template engine is to seperate code from HTML 
(or WML or whatever you are using for the UI).

Personally, the most pressing reason I have used template engines has been to 
make it easy for web designers who can just take my templates (which contain 
only HTML) and can edit them without having to worry about seeing PHP code.

A template engine essentially takes template files (files with HTML in them), 
replaces tags in them and then displays them.

A usage of a very simple template engine works like this:

a) you have a template file called users.tpl (containing the HTML for a user 
information screen)
b) you have two tags in user.tpl, lets say %%user_name%% and %%password%%
c) you have code in, lets say user.php, that looks like this:

$tpl = new CoolTemplateEngine();
$tpl->replace("user_name", "Bob Jones");
$tpl->replace("password", "walk3r");

Essentially that code opens the template engine, replaces tags with meaningful 
values and then displays it.

Obviously most template engine uses are more complicated that this.. almost 
all will contain some sort of "block" functionality and the ability to loop 
and possibly have conditional statements. From what I hear SMARTY pretty much 
has a mini scripting language embedded into it!

Essentially all template engines do these steps (though in slightly different 

(1) open a template
(2) replace tokens (aka tags) in the template with meaningful data
(3) display the template with the replaced tokens

Hope that helps...

Mark Nenadov,
Freelance Software Developer
web: http://www.freelance-developer.com

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to