Include_once ("./comm/smarty.class.php"); Contains the Smarty class file
$smarty = new Smarty (); Establish the Smarty instance object $smarty
$smarty->templates ("./templates"); Set up a template directory
$smarty->templates_c ("./templates_c"); Set compilation directory
Look, I'm the new ****//I'm joining here.
$smarty->cache ("./cache"); Set the cache directory
$smarty->cache_lifetime = 60 * 60 * 24; Set Cache time
$smarty->caching = true; Set Cache mode
//----------------------------------------------------
Left and right boundary character, default to {}, but practical application is easy with JavaScript
It is a conflict, so it is recommended to set up <{}> or other.
//----------------------------------------------------
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$smarty->assign ("name", "Li X.J."); Make template variable substitution
Compile and display the Index.tpl template located under./templates
$smarty->display ("Index.tpl");
?>
We can see that the Smarty program part is actually a set of code that conforms to the PHP language specification, which we'll explain in turn:
1. /**/statement:
The included section is the program header comment. The main content should be the role of the program, copyright and author and writing time to do a simple introduction, which is not required in Smarty
Required, but in terms of the style of the program, this is a good style.
2. Include_once statement:
It will install the Smarty file to the Web site into the current file, note that the included path must be written correctly.
3. $smarty = new Smarty ():
This sentence creates a new Smarty object $smarty, a simple instantiation of an object.
4. $smarty->templates (""):
This sentence indicates the path of the $smarty object when using the TPL template, which is a directory in which the default template path is smarty the current directory templates
Table of contents, the actual writing process, we have to write this sentence, which is also a good procedural style.
5. $smarty->templates_c (""):
This sentence indicates the directory at which the $smarty object was compiled. In the template design we already know that Smarty is a compiled template language, and this directory is what it compiles
Template directory, note that if the site is located on a *nix server, make sure that the directory defined in Teamplates_c has write-readable permissions, by default it compiles the directory
is the current directory of Templates_c, for the same reason we write it clearly.
6. $smarty->left_delimiter and $smarty->right_delimiter:
Indicates the left and right delimiters when a template variable is found. "{" and "}" by default, but in practice because we want to use it in the template
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.