Usage of HTML_Template_IT template class in PEAR_PHP tutorial

WBOY
Release: 2016-07-13 17:27:58
Original
983 people have browsed it

HTML_Template_IT in PEAR is a simple and easy-to-use class. ********** Create a template file**************** The "symbol" naming rule is the following regular expression: {[0-9A-Za- z_-]+} "Block" format is as follows, the naming rules of block names are the same as "symbol": ...Block content... Blocks allow nesting, you must first set and analyze The innermost block, and then the blocks on the upper level are set and analyzed. *********** Main method************ Constructor: void IntegratedTemplate::IntegratedTemplate ([string $root = ""]) $root = template root directory You can also use the void IntegratedTemplate::setRoot (string $root) method to set the template directory; this method cannot be called statically. -------------------------------------------------- ------- Load template: boolean IntegratedTemplate::loadTemplatefile (string $filename, boolean [$removeUnknownVariables = TRUE], boolean [$removeEmptyBlocks = TRUE]) $filename = template file name $removeUnknownVariables = Set whether to remove unknown The variable $removeEmptyBlocks = sets whether to remove empty blocks and returns TRUE if successful, and FALSE if failed. This method cannot be called statically---------------------------------------------- ----------- Specify the current block to be processed: boolean IntegratedTemplate::setCurrentBlock ([string $block = "__global"]) $block = block name Returns TRUE if successful, or a PEAR_Error object if failed. It contains a description of the error. This method cannot be called statically. -------------------------------------------------- ----- Use a variable to replace the "symbol" in the block currently being processed: void IntegratedTemplate::setVariable (mixed $placeholder [, mixed $variable = ""]) $placeholder = the name of the symbol to be replaced, if $variable is an array, then use the symbol name as the index of the array and replace the symbol with the data of the array element at this index $variable = variable name or array name This function cannot be called statically------------ ----------------------------------------------- Analyze the block currently being processed : void IntegratedTemplate::parseCurrentBlock () will return a PEAR_Error object if it fails, which contains the error description. This method cannot be called statically. -------------------------------------------------- ------- Processing completion output: void IntegratedTemplate::show ([string $block]) $block = the block to be returned. If $block is not set, the complete template will be returned ********* ********** Simple example (the example comes from PEAR's online manual)***** Usage Example Example 25-1. main.tpl.htm template file, in the "./templates" directory {DATA} Example 25-2. PHP script array("Stig", "Bakken"), "1" => array("Martin" , "Jansen"), "2" => array("Alexander", "Merz") ); $tpl = new HTML_Template_IT("./templates"); $tpl->loadTemplatefile("main.tpl.htm", true, true); foreach($data as $name) { foreach($name as $cell) { // Assign data to the inner block $tpl->setCurrentBlock("cell") ; $tpl->setVariable("DATA ", $cell) ; $tpl->parseCurrentBlock("cell") ; } // Assign data and the inner block to the // outer block $tpl->setCurrentBlock("row") ; $tpl->parseCurrentBlock(" row") ; } // Output $tpl->show(); ?> Example 25-3. Output Stig Bakken Martin Jansen Alexander Merz ************** ***************************************** There is also an ITX class in HTML_Template_IT, which can To complete more complex functions, inherit from IT class; ITX. The original code of the PHP file contains the method description of this class. For detailed instructions on other methods of HTML_Template_IT, please refer to the PEAR manual at http://pear.php.net/manual/en/package.html.html-template-it.php -- I hope everyone can make good use of the PEAR library Write more and better PHP programs! --

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531828.htmlTechArticleHTML_Template_IT in PEAR is a simple and easy-to-use class. ********** Create a template file**************** The "symbol" naming rule is the following regular expression: {[...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template