Basic concepts about PHP template skills

Source: Internet
Author: User
If you are designing an interactive website, you will certainly pay attention to two important titles: Art and program. This is also the most important factor for a website to put aside its content during construction. There are usually two ways to reconcile the relationship between the artist and the program. if you are designing an interactive website, you will certainly pay attention to two important headers: the artist and the program. This is also the most important factor for a website to put aside its content during construction. There are usually two ways to reconcile the relationship between the artist and the program:

1. complete the art page first, and then the programmer directly inserts ASP, JSP, PHP and other program code into the HTML file on the art page.

2. the artist and the program are both carried out at the same time. However, because there is no page framework, the program can only make some key code. after both parties have completed the process, the artist's page and program code will be embedded and merged again.

In the actual website construction process, due to staff, progress and other environmental restrictions, we usually use the above two methods in a hybrid manner. However, both methods have shortcomings:

1. low efficiency. Poor coordination between the two may lead to waiting, repeated code debugging steps, and other phenomena;

2. poor debugging. Because the program code needs to be embedded in the HTML page, the Code embedding, debugging, and error correction are cumbersome;

3. inconvenient protection. Once the artist's design needs to be corrected, such as the website revision, all the pages with mixed programs and HTML code must be rewritten;

If you are building a website using the PHP program, congratulations! the PHP template skills will perfectly solve the above title.

So what is the PHP template technique? PHP Template is the Template technique of PHPlib. it is one of the important modules in the PHPLIB library and developed from the Perl Template. PHPLIB is an extension of PHP, which provides many class libraries to conveniently implement some basic functions such as user authentication and database encapsulation. We can download the latest version of phplib.netuse.de. To apply a PHP template, you only need to unbind the template. inc file from the PHPLIB package and put it in the directory that our PHP program can call.

The mysterious veil is removed, and the core concept of the template technique is simple and heartbeat: to specify your art page as a template file, you only need to output the content of the movement in the page, such as the database, user interaction and other variables are defined as the corresponding position of {variable} variables in the template file. when the user browses, the PHP program file opens the template file, replace the variables defined in the template file with the corresponding database output or user interaction, for example:

Define the Template File: Mytemplate.html

The content of Mytemplte.html is:

  

.....

  

...

...

  

  

As we can see, in fact, a template file is a common HTML file, which contains the layout, art, and other elements you want, and the internal motion content exists as variables, and wait for the change. Obviously, it is meaningless to directly browse the template file. because it does not contain any PHP program, all the content is "dead". now let's take a look at how to call the template, let it "exercise.

Assume that the preceding template is applied to the test. php file. when you browse the test. php file, the process of processing the test. php file is as follows:

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.