The template function in phplib is indeed very useful, but there is a fatal small error that needs to be corrected.

Source: Internet
Author: User
Template in phplib. inc contains a template class, which can be used to separate program code from the interface, which brings great convenience to program design and interface design, and its implementation is better than quick template. However, there is a fatal small error that causes the set_block () function to fail to be used normally, and this function is very important. it looks like a template in phplib when processing duplicate blocks. inc contains a template class that can be used to implement program code and
The separation of interfaces brings great convenience to program design and interface design, and its implementation is faster
The template is better. However, there is a fatal small error that causes the set_block () function to fail to work normally.
Functions are very important, and they are very useful when processing duplicate blocks.
The following is a simple example to illustrate the usage and solution:
Template File: page1.ihtml)


{TITLE}



ID: {ID}

NAME: {NAME}





File processing: test. php
Include ("./template. inc ");
# Create template variable $ t
$ T = new Template (".", "keep ");
# Define the reference of the page variable so that you can use page1 to reference the page.
$ T-> set_file ("page1", "page1.ihtml ");
# Extract a block named TBK and point it to the reference of tbks.
$ T-> set_block ("page1", "TBK", "tbks ");
# Replacing the TITLE variable
$ T-> set_var ("TITLE", "my test of template ");
# Define the ID and NAME, and then append the TBK to tbks
For ($ I = 1; $ I <= 3; $ I ++ ){
$ N = $ I;
$ Nn = $ I * 10;
$ T-> set_var (array ("ID" => $ n, "NAME" => $ nn ));
$ T-> parse ("tbks", "TBK", true );
}
# Final output page
$ T-> pparse ("out", "page1 ");
?>
However, this example cannot be run. Openball, a netizen, once provided a solution
$ T-> set_block ("page1", "TBK", "tbks"); changed to $ t-> set_block ("page1", "TBK ", "{tbks}"); pay attention to the last "{}" symbol. this can indeed be used,
But there is a better solution. open the template. inc file and find
$ Str = preg_replace ($ reg, "{$ name}", $ str); haha, no,
Phplib has already done the processing, but forgot (I guess :) to escape "{", so modify this sentence
$ Str = preg_replace ($ reg, "\ {$ name}", $ str. In this way,
Phplib's built-in examples can also be used, and this method seems more standard.
For more information, see the templates and programs I have used.
Template: http://myjingpin.com/tpl/v1/show.html
Program: http://myjingpin.com/app/v1/show.php? Mid = flash

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.