Getting started with configuring and using the Smarty environment and getting started with the smarty Environment
This article describes how to configure and use the Smarty environment. 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:
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01
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 = "{#"; // Redefine the boundary because the default boundary "{}" is, when embedding a js script file in an html page to write code segments, the "{}" character is used. The custom boundary character can also be <{}>, $ smarty-> right_delimiter = "#}"; $ hello =" Hello World! "; // Value $ smarty-> assign (" hello ", $ hello); // reference the Template File $ smarty-> display ('index. tpl ');?>
(3) execute index. php to see Hello World! .