The Smarty technology is the essence of PHP. With the gradual improvement of PHP version, many of the original methods may be too outdated. Next I will talk about how to configure the latest PHP5.1.1 version.
The following is a step by step. Please note:
1. Download the template library file from the official website.: Http://smarty.php.net/download.php
After downloading the file, decompress it and you will see a folder named smarty. x. x. Open it and there is a libs folder. OK. Note that this is what we want.
2: under your website directory, for example, my php websiteIIS is under d:/web/php on the physical hard disk. Create a folder named test under this folder. Then, copy the folder named libs to the directory named test. {* Please refer to the comment TIPS1 at the end of this article}
3: create four more folders under the test folder;
Cache
Configs
Templates
Templates_c
4: create a file text.htm:
Copy codeThe Code is as follows: <Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> <{$ title}> </title>
</Head>
<Body>
<{$ Content}>
</Body>
</Html>
Save it in the templates directory.
5: create a file template configuration file: config. php
Copy codeThe Code is as follows: <? Php
Include "../libs/Smarty. class. php ";
$ NowPathArray = explode ("test", str_replace ("\", "/", dirname (_ FILE __)));
@ Define ("root_path", $ NowPathArray [0]);
@ Define ('_ SITE_ROOT', root_path. "test ");
$ Tpl = new Smarty ();
$ Tpl-> template_dir = _ SITE_ROOT. "/templates /";
$ Tpl-> compile_dir = _ SITE_ROOT. "/templates_c /";
$ Tpl-> config_dir = _ SITE_ROOT. "/configs /";
$ Tpl-> cache_dir = _ SITE_ROOT. "/cache /";
$ Tpl-> left_delimiter = '<{';
$ Tpl-> right_delimiter = '}> ';
?>
Save it in the main directory named test.
6. Create the test. php file in test, and enter:
Copy codeThe Code is as follows: <? Php
Require "config. php ";
$ Tpl-> assign ("title", "The test is successful. This is the title ");
$ Tpl-> assign ("content", "this is content ");
$ Tpl-> display('test.htm ');
?>
7: test. php In the browser:
This is content
Congratulations, the configuration is successful. Otherwise, the configuration fails and check whether it is as I said.
Tips1: to use Smarty technology globally on the website, we can modify
<B>
Windows: "path1; path2"
Include_path = ".; c: phpincludes"
</B>
Changed:
------------------->
Windows: "path1; path2"
Include_path = ".; c: phpincludes; d: webwebphplibs"
Use the template in the same way as before. Do not
Include "../libs/Smarty. class. php ";
Just use it.