The basic construction of the smarty template and the creation of the smarty Template
1. Download the smarty template, which is officially available
2. decompress the package. You will need a directory like this.
You can delete all the files except the libs folder (I Don't Know What To use ).
3. Create them in the current directoryTemplates, templates_c, cache, configFolder, other names are also allowed, but you need to modify the configuration file
4. Create a folder under the root directory. Create a PHP file and paste the following code into it.
Require_once ("libs/smarty. class. php ");
$ Smarty = new smarty ();
$ Smarty-> template_dir = "templates"; // specify the path of the template file
$ Smarty-> compile_dir = "templates_c"; // specify the compiled file path
$ Smarty-> cache_dir = "cache"; // specify the cache file path
$ Smarty-> config_dir = "config"; // specify the path of the smarty configuration file
$ Smarty-> left_delimiter = "<{"; // specify the left delimiter to avoid conflicts with JS.
$ Smarty-> right_delimiter = "}> ";
$ Smarty-> assign ("name", "familiar with frameworks"); // registers Variables
$ Smarty-> display ("index. tpl"); // display template
5. Next, create the index. tpl template file in the templates folder and display the variable value. The content is as follows:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>
</body>
6. Run the PHP file and he will return an error like this.
This is the case because the path of the configuration file is incorrect. This error is reported because the file not being executed is not in the root directory.
7. The most basic smarty framework has been built. The main reason is that path problems may lead to mistakes.
This indicates that there is no problem with the file to be introduced, but the configuration is wrong, as shown below, it is easy for new users to gain a circle.