[Original] comparison between Smarty2 + and Smarty3 + (1): smarty execution mechanism

Source: Internet
Author: User
[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:

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.