Template class

From: Date: Thu, 29 Nov 2001 16:25:58 +0000
Subject: Template class
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-3188@lists.php.net to get a copy of this message
Not wanting to get into a debate of which template engine is better or why, I have a template class I think would be useful in pear. As I understand it multiple classes with the same purpose (ie multiple template classes) are ok (no doubt many people will want to see their favourite template parse in pear :D ). So, comments? There's the source, a script and an example template here: http://www.phpguru.org/template/ Here's a brief overview of the api: $obj->load_file(string handle, string filename); Loads a file into the objectand assigns it to the given handle. $obj->register(string handle, array variables); Registers the key/value pairs in the array as variables in the template Similar to phplib templates set_var IIRC. $obj->parse(string handle); Parses the registered variables in the specified template. $obj->parse_loop(string handle, string loop_name, array data); Loops are dynamic blocks, ie build entire table from one row with the info in the data array. $obj->parse_if(string handle, string if_name, mixed data); Parse the named if condition based on data. $obj->parse_all(string handle); This function will try to find and parse everything it can in the template. Ifs, loops and normal variables. $obj->print_file(string handle, ...); Prints the given template(s). Takes any number of handles as arguments. $obj->return_file(string handle); Returns the given template(s). Takes any number of handles as arguments. If multiple are given, the templates will be concatenated. Thats the core functions, there's also some others which server as shortcuts to (ie combinations of) the above. -- Richard Heyes "If you have any trouble sounding condescending, find a Unix user to show you how it's done." - Scott Adams

« previous php.pear.dev (#3188) next »