Well, a very basic example of a template would be like this.
Code: Select all
<html>
<head>
<title>{title}</title>
</head>
<body>
<table>
<tr>
<td>{header}</td>
</tr>
<tr>
<td>{body}</td>
</tr>
<tr>
<td>{footer}</td>
</tr>
</table>
</body>
</html>
This template has 4 tags. Title, header, body and footer. This template would be saved to a file like "mytemplate.tpl". Your template parser and display functions/classes would work like this:
Code: Select all
<?php
//do our needed includes
include 'templateparser.php';
include 'display.php';
//here we'll set our tags
$tags['title'] = "My Hello World Page";
$tags['header'] = "This is the header to my Hello World page.";
$tags['body'] = "Hello World";
$tags['footer'] = "This is the footer to my Hello World page.";
//we may have some other code in here
$output = templateparser::parse($tags, "mytemplate.tpl");
//now we'll call our display page
display($output);
?>
Basically all your template parser would do is take your $tags key names, add the "{...}" to create the tag, and then do a str_replace on the contents of the template file with the $tags values. It would then return the resulting HTML code. Your display function would then do any outputting to the browser.
Your tags can be in any format you like. I chose "{tag}", but you could choose anything. "&tag&", "%tag%", "%tag&" ...
Granted this is a very basic example, but it should give you an idea of how it works.
Now if you are looking for an example of a framework, these typically are not simple enough to post an example here. If you do a google search on "php simple framework" there are some good examples out there.