"Original" Smarty and Smarty comparison (i): Smarty implementation Mechanism

Source: Internet
Author: User
Smarty is a template engine-the separation of the background logic and the front-end style, the source code is written in PHP. Website address: http://www.smarty.net/

After downloading the latest 3.1 version, there will be a demo folder, directly in the machine's web directory to execute the demo is a simple Smarty application. It is very easy to use smarty according to the documentation or the configuration in the demo.

The basic file directory and code are as follows:

Templates and Templates_c Two folder configuration is necessary, templates is the directory of HTML templates, Templates_c is to compile HTML into an executable directory of PHP files.

Smarty Two basic functions assign and Display,assign are parameters (exactly: aggregate the data required by the foreground, and assign values in a unique array in the form of k-v), display is to find the displayed page (the array that receives the Assign, Output array Data display page). In the final analysis, Smarty finally executes the compiled PHP file, with the PHP echo, foreach and other native functions and syntax output content, under the Templates_c folder, are stored in the end of PHP files.

Basic mechanisms for implementation of smarty2+ and smarty3+

A simpler process is as follows:

Compiled index.tpl.php file:

        
 
  $val) {        echo "

". $key." --". $val."

"; } ? >

Last index.php to run the file:

$arr = Array ("name" = "ABC", "tel" = "2222", "age" = "2111");  1, the HTML compiled into PHP (omit the complex smarty tag replaced with PHP tags)  //2, omit the intermediate complex compilation file naming, File introduction/write and cache case  //3, include compiled PHP file, and execute, Note that the $arr array at this time can use the output  include "index.tpl.php" in index.tpl.php;

However, compared to the smarty3+ version of the "100% rewrite", whether in the PHP new syntax or compile execution performance, the following is the two versions of the official demo and the version of the analysis diagram, left is 2.6.18, the right side is 3.1.30 Version:

  • 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.