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

A Strict() Master - 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
While the methods discussed above will suffice for most of your FastTemplate requirements, the class also comes with a bunch of ancillary capabilities.

The strict() method is used to display an error if FastTemplate finds template variables without any values assigned to them; these undefined variables will also appear as is in the final output.

<? // strict error checking $obj->strict(); ?>
The opposite of this is the no_strict() method, which replaces these unassigned variables with empty strings.

<? // turn off error checking $obj->no_strict(); ?>
The fetch() method returns the raw data which results from a parse() operation. Consider the following:

<? // parse templates $obj->parse(RESULT, "list"); // print echo $obj->fetch("RESULT"); ?>
The clear() method is used to clear variables.

<? // parse templates$obj->parse(RESULT, "list");// clear$obj->clear("RESULT");// prints nothing$obj->FastPrint("RESULT");?>
The get_assigned() method is used to obtain the value of any FastTemplate variable.

<? $obj->assign("EMAIL", "jdoe@somewhere.com"); // returns "jdoe@somewhere.com" echo $obj->get_assigned("EMAIL"); ?>
And finally, the utime() function comes in handy when you need to measure script execution time.

<? // list.php - item list // include class file include("class.FastTemplate.php3"); // instantiate new object $obj = new FastTemplate("./tmpl/"); // get start time $begin = $obj->utime(); // assign names for template files $obj->define(array( "list" => "list.tpl", "list_item" => "list_item.tpl" )); // get item list // assume it looks like this.. $items = array("vanilla", "pineapple", "strawberry", "chocolate chip", "peach", "banana", "grape"); // build LISTCONTENT variable by concatenation of multiple instances of "list_item" template for ($x=0; $x<sizeof($items); $x++) { $obj->assign("ITEM", $items[$x]); $obj->parse(LISTCONTENT, ".list_item"); } // parse templates $obj->parse(RESULT, "list"); // and print $obj->FastPrint(RESULT); // get end time $end = $obj->utime(); // print script execution time echo "Done in " . sprintf("%01.3f ", ($end - $begin)) ." seconds."; ?>


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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap

Dev Shed Tutorial Topics: