: This article describes how to install and tune the Smarty3 module of php. For more information about PHP tutorials, see. When using the Smarty template, in order to split the user interface and business data
Install Smarty, official download URL: http://www.smarty.net/download.php
After decompression, you only need to copy the "libs" folder in the folder to the root directory.
In libs, only the Smarty. class. php class php is used.
Create the file to be used in the root directory
Here, tpls: Template directory, coms: generated Directory. during development, this directory should not be placed under the root directory of the web server.
Create a demo.html file under the tplsdirectory, which is a presentation layer interface
<{ $title }> <{$content}>
<{$content}>
<{$content}>
《script》if(true){alert(new Date());}《script》
In init. inc. php, it is used to store php initialization code.
Similarly, you must set the template file storage directory and compilation Directory. to prevent conflicts with spaces, we can modify the delimiters.
It should be emphasized that the fixed Directory of the specified output can be called not only in the root directory, but also in the external directory.
SetTemplateDir (ROOT. "/tpls")-> setCompileDir (ROOT. "/coms"); // specify the compiling Directory // modify the delimiter to prevent conflicts with spaces $ smarty-> auto_literal = false; // The default value is true, false does not conflict with spaces $ smarty-> left_delimiter = "<{"; $ smarty-> right_delimiter = "}> ";
Demo. php is the main file, mainly using the assign () method to implant variables into the template, and then using the display () method to output web pages
assign("title","11111111"); $smarty->assign("content","2222222222"); $smarty->display("demo.html");
The basic usage of Smarty is like the above, but this is only a small part of Smarty. Smarty is a very powerful template.
The above describes how to install and tune the Smarty3 module of php, including some content. I hope my friends who are interested in the PHP Tutorial will be helpful.