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 output file. Please refer to the manual for specific applications of smarty. Here we only explain its functional principles.
Record the problems encountered by smarty cache.
If smarty cache is enabled, the compiled output file will be saved in the cache directory when executed for the first time. In the program, smarty’s is_cache() function is used to detect whether the cache file has expired. If it expires, the cache will be updated. If it has not expired, the cache file will be automatically called, eliminating the compilation process. Detecting cache expiration is to see whether the template file has changed within the specified life cycle. The change here is achieved by detecting the latest modification time of the file, not by detecting the content of the template file.
Prevent 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 reloading this 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 be sure it won't be cached like the rest of the page.
http://www.bkjia.com/PHPjc/477813.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477813.htmlTechArticlephp is an embedded HTML scripting language. In order to separate HTML and php code, the so-called logic layer and presentation layer , which is what template engines are for. In order to achieve this purpose, the template engine needs to have...