The usage of html_template_it in pear _php

Source: Internet
Author: User
Keywords usage method BLOCK TD return TD Symbol template set
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_-]+}
The "block" format is the following, with the block name naming convention and 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 methods ***********
constructor function:
void Integratedtemplate::integratedtemplate ([String $root = ""])
$root = Touch Plate root directory
You can also use
void Integratedtemplate::setroot (String $root)
method to set the template directory; The method cannot be called statically.
---------------------------------------------------------
To load a template:
Boolean Integratedtemplate::loadtemplatefile (String $filename, Boolean [$removeUnknownVariables = TRUE], Boolean [$ Removeemptyblocks = TRUE])
$filename = Template file name
$removeUnknownVariables = Sets whether the unknown variable is removed
$removeEmptyBlocks = set whether to remove empty blocks
The success returns True, and the failure returns false.
The method cannot be called statically
-------------------------------------------------------
Specify the block currently being processed:
Boolean Integratedtemplate::setcurrentblock ([String $block = "__global"])
$block = block Name
Successful return True, Failure returns a Pear_error object containing an error
Describe. 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 = The symbol name to replace, if $variable is an array,
Then use the symbol name as the index of this array and use the cable
Data substitution symbol for an array element that is cited
$variable = variable name or array name
The function cannot be called statically
--------------------------------------------------------
Parse the block currently being processed:
void Integratedtemplate::p arsecurrentblock ()
Failure will return a Pear_error object containing an error
Describe. The 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 full template will be returned


Simple example (sample from Pear's online manual) * * * * * *
Usage Example
Example 25-1. main.tpl.htm template file, under the "./templates" Directory











{DATA}




Example 25-2. PHP script

Require_once "html/template/it.php";

$data = array
(
"0" = = 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



*******************************************************
Html_template_it also has a ITX class that can perform more complex functions,
Inherit from 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, please refer to the Pear manual at
http://pear.php.net/manual/en/package.html.html-template-it.php

--Hope you can make good use of pear this library to write more and better PHP programs! --
  • Related Article

    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.