Smarty learning notes 5 template compilation

Source: Internet
Author: User

Template compilation of smarty is one of its most powerful functions. When you read a template file for the first time, smarty automatically creates a PHP script file in the compilation directory based on your template file, that is, compile the file. When you access the template file again, smarty reads the compiled file instead of the real template file. It also automatically determines whether the template file has been updated, if the template file has been updated, it will generate a new compilation file.
Some attributes and methods of compiling files
$ Compile_dir
Used to set the path information for storing the compiled file. The default is./templates_c, which is the templates_c directory under the directory where the current PHP script is located. For example:

 
1 $ Smarty-> Compile_dir = 'lib/smarty/templates_c ';

 

Setcompiledir (string compile_dir );
With the $ compile_dir variable function, it is used to set the storage path of the compiled file.
Note: We recommend that you use this method to set the path of the compiled file.

 1 <? PHP  2   3   //  Set the storage path of the compiled file 4   $ Smarty -> Setcompiledir ('./templates_c' );  5   6   //  Chaining of method CILS  7   $ Smarty -> Settemplatedir ('./templates' )  8 -> Setcompiledir ('./templates_c' )  9 -> Setcachedir ('./cache' ); 10   11 ?>

 

Getcompiledir ()
Used to obtain the path information for storing compiled files

 
1<?PHP2 3 //Get directory where compiled templates are stored4 $ Compiledir=$ Smarty->Getcompiledir ();5 6?>

 

$ Compile_check
If this variable is set to true, you can determine whether the template content has changed before each display of the template file. If the template file has changed, the compilation file is regenerated, otherwise, an existing compilation file is used. If no template compilation file exists, smarty ignores this setting and always generates a compilation file. The default value is true.
Note: When the applicationProgramThis option should be disabled to obtain the maximum performance when it is used (the template file will not be changed.
Note: If this option is disabled, the changed content will not be displayed when the template file is changed unless the compilation file is regenerated.
In Versions later than smarty3.1, you can set this variableSmarty: compilecheck_cachemissWhen a cache file needs to be generated, the compilation file will be checked for validity. Therefore, when a cache file expires, the compiled file will be checked for validity before the cache file is generated.
$ Force_compile
If this value is set to true, the compilation file is forcibly re-generated every time the template file is requested. This option ignores $ compile_check. The default value is false. Opening the secondary option is a good choice during development. If the cache file is enabled, the cache file will also be forcibly re-generated at each request.
$ Compile_locking
This option is used to prohibit multiple compilation of the same template within the same time. The default value is true. To disable the function, set the value to false.
$ Compiler_class
Specifies the class file called when the compilation file is generated. The default class is smarty_compiler.

 

Related Article

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.