The usage of html_template_it in pear _php Tutorial

Source: Internet
Author: User
Tags pear
The Html_template_it in pear is a simple and easy-to-use class. Create a template file **************** the "symbol" naming convention is the following regular expression: {[0-9a-za-z_-]+} "block" format is the following, the name of the block name is the same as "symbol": ... Block content ... Blocks allow nesting, you must first set up and analyze the inner blocks, and then set and analyze the blocks on the previous layer. Main method *********** constructor: void Integratedtemplate::integratedtemplate ([String $root = ""]) $root = Touchpad root directory you can also use V The OID integratedtemplate::setroot (String $root) method sets the template directory, and the method cannot be called statically. ---------------------------------------------------------Load Template: Boolean integratedtemplate::loadtemplatefile ( String $filename, Boolean [$removeUnknownVariables = True], Boolean [$removeEmptyBlocks = True]) $filename = template file name $remove Unknownvariables = Sets whether to remove the unknown variable $removeEmptyBlocks = Sets whether to remove the empty block successfully returns TRUE, the failure returns false. The method cannot be called statically-------------------------------------------------------specifies the block currently being processed: Boolean integratedtemplate:: Setcurrentblock ([String $block = "__global"]) $block = The block name successfully returns TRUE, and the failure returns a Pear_error object containing the error description. The method cannot be called statically. -------------------------------------------------------Replace the "symbol" in the block currently being processed with a variable: void integratedtemplate::setvariable ( Mixed $placeholder [, Mixed $variable = ""]) $placeholder = symbol name to replace, if $variable is an array, use the symbol name as the index of the array and replace the symbol with the data of the array element of the index $ Variable = variable name or array name the function cannot be called statically--------------------------------------------------------parse the block currently being processed: void Integratedtemplate:: Parsecurrentblock () failure returns a Pear_error object that contains an error description. The method cannot be called statically. ---------------------------------------------------------processing complete output: void Integratedtemplate::show ([string $block]) $ block = blocks to be returned if $block is not set, the full template ******************* Simple example (sample from Pear's online manual) is returned * * * * * * * * * Usage Example Example 25-1. main.tpl.htm template file, under 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. OutputStig Bakken Martin Jansen Alexander MerzHtml_template_it also has a ITX class that can perform more complex functions, inheriting from the It class; ITX. The original code of the PHP file contains the method description for this class. For a detailed description of the other methods of html_template_it, refer to Pear's manual at http://pear.php.net/manual/en/package.html.html-template-it.php- I hope you can make good use of pear this library to write more and better PHP programs! --

http://www.bkjia.com/PHPjc/531828.html www.bkjia.com true http://www.bkjia.com/PHPjc/531828.html techarticle the html_template_it in pear is a simple and easy-to-use class. Create a template file **************** the "symbol" naming convention for the following regular expression: {[...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.