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