: This article mainly introduces Smarty-1 (18). For more information about PHP tutorials, see. Smarty
I. Template principles
1. Why use a template?
1) scenario:
For ($ I = 0; $ I <$ count; $ I ++ ){
Echo''. $ Row ['proname'].'
}
The above code is used to mix html and php, which is not conducive to development and maintenance.
2) scenario:
We have developed a website. after a period of operation, the customer is not satisfied with the front-end. we have developed another interface. However, after the operation, the customer thinks that the previous style is better, frequent changes to website styles
The best way to solve the above two problems is to use the template
2. implementation of the template
The template is actually a string replacement.
1) Example 1
Template File:
Php file:
1) Example 2:
Template class:
PHP code:
The code in the above class file is not optimized enough. we can use a popular template framework to implement our own project.
1. Introduction to Smarty
1. what is Smarty?
Smarty is a PHP template engine developed based on PHP. It provides the separation of logic and external content.
2. Smarty features
L speed
L compilation type
L cache technology
L plug-in technology
L free statement if/elseif/else/endif
L Real-time update: high real-time requirements
3. configuration
Http://smarty.php.net
L/lib
L Smarty 2.6 php4.0
L Smarty 3.0 php5.0
1. decompress the smarty file and enter the decompressed directory.
Demo: Case
Libs: Smarty source code
1) go to the libs Directory,
Plugins: Custom plug-in Directory
Sysplugins: System plug-in Directory
Debug. tpl: there is a debugging function in Smarty. you can observe the variable value and Debug window template.
Smarty. class. php: Smarty core class file (entry file)
SmartyBC. class. php: Smarty3.0 is upgraded based on 2.0. to use the 2.0 feature, you can reference this portal file.
3) copy the libs directory to the project and rename it
The above introduces Smarty-1 (18), including some content, and hope to be helpful to friends who are interested in PHP tutorials.