Php smarty template engine

Source: Internet
Author: User
Php's smarty template engine php is an embedded HTML scripting language. in order to separate HTML and php code, the so-called logic layer and presentation layer, this is the purpose of the template engine. To achieve this purpose, the template engine must have the following functions: 1. store variables; 2. read template files; 3. generate output based on the first two. The Code is as follows: test01.php & lt ;? Php $ php smarty template engine

Php is an embedded HTML scripting language. to separate HTML and php code, namely, the logic layer and the presentation layer, this is the purpose of the template engine. To achieve this purpose, the template engine must have the following functions:
1. store variables;
2. read the template file;
3. Combine the first two to generate the output.
The Code is as follows:
Test01.php
$ Name = 'xiaoshenge ';
?>
Test02.php

Test

Name =


Test03.php
Include 'test01. php ';
Include 'test02. php;
?>
Of course, this is just a simple simulation of how to implement the functions of the php template engine. the famous smarty in the php open-source community encapsulates the above functions. Save Data> load Template> compile and generate an output file. For more information about the smarty application, here is just an explanation of its functional principles.

Record the problems encountered by the smarty cache.

If the smarty cache is enabled, the compiled output file will be saved to the cache directory during the first execution. in the program, the smarty is_cache () function is used to check whether the cache file has expired, if it expires, the cache will be updated. if it does not expire, the cache file will be automatically called, saving the compilation process. Check whether the template file is changed within the specified lifecycle. the changes here are implemented by checking the latest modification time of the file, not the template file content.
Block the entire template file from being cached:
Index. php:
Require ('smarty. class. php ');
$ Smarty = new Smarty;
$ Smarty-> caching = true;
Function smarty_block_dynamic ($ param, $ content, & $ smarty ){
Return $ content;
}
$ Smarty-> register_block ('dynamic ', 'smarty _ block_dynamic', false );
$ Smarty-> display ('index. tpl ');
Index. tpl:
Page created: {"0" | date_format: "% D % H: % M: % S "}
{Dynamic}
Now is: {"0" | date_format: "% D % H: % M: % S "}
... Do other stuff...
{/Dynamic}
When you reload the page, you will notice that the two dates are different. One is "dynamic" and the other is "static ". You can do anything between {dynamic}... {/dynamic} and ensure that it will not be cached like the rest of the page.


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.