The basic construction of the smarty template and the creation of the smarty Template

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.