Here is how I understand templates to be.
I have a template called atriclebox. Inside this template is all of the HTML that I need to display an article on my site. This HTML is designed without any knowledge of my code and what it does. So I can just bring up this HTML page and see that everything looks correct:
<!-- Article Box Template -->
<table>
<tr><th>#ARTICLE_TITLE#</th></tr>
<tr><td>#ARTICLE_BODY#</td></tr>
</table>
Now this is a simple little template that builds a 2 row table with row one being a table header. In reality I'd put much more work into that HTML to make it look really nice and fit in with the theme of my web site. But now that I have that I can write my code to use it to generate as many article boxes as I need with some really simple code:
function buildArticle($title, $body) {
// below is a call to a function that will load the template into
// memory so I can work with it. It'd be better to write a class
// that loads the template only the first time it's called and
// stores it in memory so you could limit diskaccess.
$template = getTemplate("articlebox");
// Now that I have the template I need to fill it, and that can be
// done in many ways, but one of the easiest is to use regular
// expressions to replace information. I like [man]preg_replace[/man]()
$template = preg_replace("#ARTICLE_TITLE#", $title, $template);
$template = preg_replace("#ARTICLE_BODY#", $body, $template);
// Now I just return the completed HTML article box to my code
// for placement and display.
return $template;
}
After calling that function with a title and body of an article I'd get HTML back that is all ready to be placed in my page and displayed to my users. As either the HTML designer or the PHP coder I don't have to know anything about what the other is doing. All I need to do is agree on a standard for marking the replacement areas. I tend to use the #UPPERCASEWORD# format myself but it could be anything that you can pattern match against and that won't get any false positives in your HTML.