Initial knowledge of PHP Smarty template engine
PHP is an embedded HTML scripting language, in order to separate the HTML and PHP code, the so-called logical layer and the presentation layer, which is the purpose of the template engine. In order to achieve this goal, the template engine has the following functions: 1. Storage variables; 2. Read the template file; 3. Combine the first two generated outputs. Code is as follows:
test01.php
$name = ' Xiaoshenge ';
?>
test02.php
<title>Test</title>
Name=
test03.php
Include ' test01.php ';
Include ' test02.php;
?>
Of course, here is just a simple simulation of how to implement the PHP template engine function, in the PHP open source community, the famous smarty is encapsulated the above features. Save data, load template, compile build output file. For a specific reference manual for the application of smarty, here is simply an explanation of its functional principle.
BTW: Record the problem that the Smarty cache encounters.
If the Smarty cache is turned on, the first execution will save its compiled output file to the cache directory, in the program through the Smarty Is_cache () function to detect whether its cache file expires, if the expiration will update the cache, if not expired will automatically call the cache file, Eliminate the process of compiling. Detecting cache expiration is to see if the template file has changed over the specified life cycle, where the change is achieved by detecting the file's last modified time, not by detecting the template file contents.
Block the entire article of a template file from being cached:
index.php:
{/dynamic}
When you reload this page, you will notice that the two dates are different. One is "dynamic" and one is "static". You can be in {dynamic} ... Do anything between {/dynamic} and make sure it won't be cached like the rest of the page.
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.