Smarty installation tutorial

Source: Internet
Author: User

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.

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.