Web Development With PHP FastTemplate - You've Got Mail
(Page 4 of 9 )
A great amount of FastTemplate's power, however, lies in its ability to manage more than one template simultaneously. Consider the following HTML page:

Now, suppose I were to split this up into the following sections,

and assign each section to a template. This would mean that the header, the main form, and the footer at the bottom could be modified independently of each other - a useful capability to have.
Here are my templates:
<!-- begin: header.tpl -->
<html>
<head>
<basefont face=Verdana>
</head>
<body>
<table width=100% cellpadding=10 bgcolor="Black">
<tr><td height=30><b><font color=white>{TITLE}</font></b></td></tr>
</table>
<!-- end: header.tpl -->
<!-- begin: form.tpl -->
<p>
<i>{INSTRUCTIONS}</i>
<p>
<div align=center>
<table border="0" cellspacing="5" cellpadding="5">
<form action="mailer.php" method="post">
<tr>
<td>Name</td>
<td><input type="Text" name="name" size="15"></td>
</tr>
<tr>
<td>Email address</td>
<td><input type="Text" name="email" size="25"></td>
</tr>
<tr>
<td>Subject</td>
<td><input type="Text" name="subj" size="25"></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea name="comments" cols="35" rows="8"></textarea></td>
</tr>
<tr>
<td colspan=2 align=center><input type="Submit" value="Send Feedback"></td>
</tr>
</form>
</table>
</div>
<!-- end: form.tpl -->
<!-- begin: footer.tpl -->
<div align=center><font size=-2>
Everything here is © <a
href="http://www.melonfire.com/">Melonfire</a>, 2001. All rights
reserved.<br>
Read our <a href="tac.html">legal notices</a>, and our <a
href="privacy.html">privacy policy</a>
</font></div>
<br>
<table width=100% align=center cellpadding=0 bgcolor="Black">
<tr><td> </td></tr>
</table>
</body>
</html>
<!-- end: footer.tpl -->
And here's the script which puts them together with FastTemplate.
<?
// feedback.php - generate a feedback form using multiple templates// include class fileinclude("class.FastTemplate.php3");// instantiate new object$obj = new FastTemplate("./tmpl/");// assign names for template files$obj->define(array("header" => "header.tpl", "form" => "form.tpl", "footer" => "footer.tpl"));// assign values to FT variables within the template// as an associative array of key-value pairs$obj->assign(array("TITLE" => "Feedback Form", "INSTRUCTIONS" => "Please use the following form to send us your feedbackon this Web site"));// parse template "feedback" and store in handler "result"$obj->parse(ft_header, "header");$obj->parse(ft_form, "form");$obj->parse(ft_footer, "footer");// print contents of handler "result"$obj->FastPrint(ft_header);$obj->FastPrint(ft_form);$obj->FastPrint(ft_footer);?>
Note that, in this case, FastTemplate is parsing and printing more than one template to create a composite HTML document. Each template may be modified independently of the others, making it easier to alter just the top bar or the form fields, for example.
Next: Repeat Customers >>
More PHP Articles
More By icarus, (c) Melonfire