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
The template. inc in phplib contains a template class, which 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)
<HTML>
<HEAD>
<TITLE> {TITLE} </TITLE>
</HEAD>
<Body bgcolor = "# FFFFFF">
<! -- Begin tbk -->
ID: {ID} <BR>
NAME: {NAME} <BR>
<HR>
<! -- End tbk -->
</BODY>
</HTML>
File processing: test. php
<? 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 ");

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.