This article mainly introduces how to configure and use the Smarty environment, and analyzes in detail the meanings of setting up and configuring parameters in the Smarty environment, which is very easy to understand, for more information about how to configure and use the Smarty environment, see the following example. We will share this with you for your reference. The details are as follows:
Download Smarty (here we use Smarty-2.6.26 as an example ). Decompress the downloaded file (the directory structure is quite complex ). Next we will show you how to install an instance.
(1) create a new directory named learn/under the root directory, and create a directory named smarty/In learn /. Copy the libs/from the extracted directory to smarty/, create the templates directory in smarty/, and create cache/, templates/, templates_c/, and config/in templates /.
(2) create a new template file: index. tpl. Place the file in the learn/smarty/templates Directory. the code is as follows:
Smarty{#$hello#}
Create index. php and put this file under learn:
<? Phprequire 'smarty/libs/smarty. class. php '; $ smarty = new Smarty; // set the path of each directory. here is the installation focus $ smarty-> template_dir = "smarty/templates "; $ smarty-> compile_dir = "smarty/templates/templates_c"; $ smarty-> config_dir = "smarty/templates/config "; $ smarty-> cache_dir = "smarty/templates/cache"; // The smarty template provides the high-speed cache function. if it is true, caching is enabled, however, the webpage may not be updated immediately. you can also use other methods to solve the problem $ smarty-> caching = false; $ smarty-> left_delimiter = "{#"; // re-define the boundary. because the default boundary "{}" character is used to embed the js script file into the html page to compile the code segment, the custom boundary can also be <{}> ,{/