Home arrow PHP arrow Page 4 - Web Development With PHP FastTemplate

You've Got Mail - PHP

Typically, most PHP-based Web sites use scripts which containintermingled PHP and HTML code. While this speeds up development, it alsohas a downside: an interface designer cannot modify page layouts or HTMLtemplates without the assistance of an experienced PHP developer. Well,there's a solution to the problem - and you'll be surprised to hear thatit's been around for quite a while. Say hello to PHP FastTemplate.

TABLE OF CONTENTS:
  1. Web Development With PHP FastTemplate
  2. Who Am I?
  3. Proofing The Pudding
  4. You've Got Mail
  5. Repeat Customers
  6. Flavour Of The Month
  7. A Strict() Master
  8. Musical Chairs
  9. A Rose By Any Other Name...
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 9
September 05, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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.

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: