[Original] Comparison of Smarty2 + and Smarty3 + (1): smarty execution mechanism smarty is a template engine-namely, separating the background logic and front-end style. the source code is written in PHP. Official Website address: http://www.smarty.net/
After downloading the latest version 3.1, there will be a demo folder. running the demo directly in the web Directory of the machine is a simple usage of smarty. It is very easy to use smarty according to the document or the configuration in the demo.
The basic file directory and code are as follows:
The configurations of templates and templates_c folders are indispensable. templates is the directory of html templates, and templates_c is the directory of PHP files that can be compiled into executable HTML files.
In smarty, there are two basic functions, assign and display. assign is to pass parameters (it should be: aggregate the data required by the foreground and assign values in a k-v-shaped way in a unique array ), display is to find the page display (receiving the assign array and outputting the array data display page ). In the final analysis, smarty finally executes the PHP file after compilation, and works with native functions such as echo and foreach of PHP and syntax Output Content. in the templates_c folder, it stores all the files ending with PHP.
Basic mechanism of smarty2 + and smarty3 + execution
The simpler process is as follows:
The compiled index. tpl. php file:
$val){ echo "".$key."--".$val."
"; } ?>
Finally, the index. php file can be run:
$ Arr = array ("name" => "abc", "tel" => "2222", "age" => "2111 "); // 1. Compile the html into PHP (replace the complicated smarty tag with the PHP tag) // 2. omit complicated compilation file names, file introduction/write and cache; // 3. include the compiled PHP file and execute it, note that the $ arr array can be in index. tpl. use the output include "index. tpl. php ";
However, compared with 2 +, the smarty3 + version "100% rewrite" is applicable to new PHP syntax and compilation and execution performance, the following are the analysis charts in the official demo for versions 2 + and 3 +, with version 2.6.18 on the left and version 3.1.30 on the right: