Smarty's latest URL: http://www.smarty.net/
Http://www.smarty.net/download.php to this page
Download the latest smarty source file.
Decompress the downloaded file and copy all the files in the libs folder and directory to a new folder, such as the smarty_temp directory. Then
Create four new folders under this directory: templates, templates_c, cache, configs
Create a new configuration file: config. Inc. php. The content is as follows:
<? PHP
/*
* You only need to put this file in the same directory as templates, templates_c, cache, and configs,
* You only need to call this file elsewhere.
*
*/
// Replace D:/phpweb/myweb/smarty_temp with D:/phpweb/myweb/smarty_temp
$ Patharray = explode ('smarty _ temp ', str_replace ('/','/', dirname (_ file __)));
Define ('root', $ patharray [0]); // sets the absolute path of the website file
Define ('smarty _ root', root. 'smarty _ temp/'); // set the path of the smarty class library
Require_once 'libs/smarty. Class. php ';
$ Smarty = new smarty (); // create a new smarty object
$ Smarty-> compile_check = true; // you can check whether the content of the template file changes every time you execute PHP.
// Debugging console, which is a switch parameter. If it is enabled, the debug window showing the smarty variable and running status is displayed.
$ Smarty-> debugging = false;
// Set the template directory
$ Smarty-> template_dir = smarty_root. 'templates /';
// Default template directory name of smarty: templates_c
$ Smarty-> compile_dir = smarty_root. 'templates _ c /';
// Default template cache directory name
$ Smarty-> cache_dir = smarty_root. 'cache /';
// Default config file directory name: configs
$ Smarty-> config_dir = smarty_root. 'configs /';
// Left and right boundary characters. The default value is {}, but it is easy to conflict with Javascript in actual applications. Therefore, it is recommended to set it to <{}> or another one.
$ Smarty-> left_delimiter = '<{';
$ Smarty-> right_delimiter = '}> ';
?>
Test:
Create the test.html template file in the tmeplatesdirectory. The content is as follows:
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> <{$ title}> </title>
</Head>
<Body>
<{$ Content}>
</Body>
</Html>
Create the test. php file in the smarty_temp directory. The content is as follows:
<? PHP
Require_once 'config. Inc. php'; // You can include the test. php file anywhere.
$ Smarty-> assign ("title", "test successful, this is the title"); // replace template Variables
$ Smarty-> assign ("content", "Test Result successful"); // replace template Variables
$ Smarty-> display('test.htm'); // compile and display the index. TPL Template under./templates
?>
Run it.