UseSmartyThe maximum speed of a program can be improved, which is relative to other template engine technologies.
*/
The code is as follows: |
Copy code |
$ Servername = 'localhost '; $ Dbname = 'whois '; // database tutorial name, which must be changed to the name of the database you are currently using $ Tbname = 'post'; // data table name, no need to modify $ Name = 'root'; // database username, which needs to be modified $ Password = 'xxxxxxx'; // password of the database link, which needs to be modified Require_once 'smarty/libs/smarty. class. Php '; $ Smarty = new Smarty (); // Initialization class $ Smarty-> template_dir = "smarty/templates"; // set the template directory $ Smarty-> compile_dir = "smarty/templates/templates_c"; // Set the compilation Directory $ Smarty-> config_dir = "smarty/templates/config"; // configuration file directory $ Smarty-> cache_dir = "smarty/templates/cache ";// $ Smarty-> caching = false; $ Db = mysql tutorial _ connect ($ servername, $ name, $ password) or die ('server connection error. '); $ Ii = mysql_select_db ("$ dbname") or die ("cannot select database "); Mysql_query ("set names 'gbk '"); $ Title = 'smarty '; $ Keyword = 'smarty template, smarty tutorial '; $ Description = 'simple smarty getting started tutorials '; $ Smarty-> assign ('title', $ title ); $ Smarty-> assign ('keyword', $ keyword ); $ Smarty-> assign ('Description', $ description ); $ Smarty-> display('index.html '); // use the smarty emplates emplatesindex.html Template |
?>
Index.html template file
The code is as follows: |
Copy code |
<Title> <! -- {$ Title} --> </title> <Meta name = "keywords" content = "<! -- {$ Keyword} --> "/> <Meta name = "description" content = "<! -- {$ Description} --> "/> {Include file = 'head. tpl '} {Include_php file = 'Body. Php '} {Include file = 'footer. tpl '} |
<?
/*
Smarty Template variables
. {$ Name}: template variable, which is the core component of smarty. It is included in the left boundary {and right boundary} defined by smarty and provided in the form of a PHP variable. It will be used in the smarty program.
$ Smarty-> assign ("name", "Li Xiaojun"); replace the $ name in the template with the word "Li Xiaojun.
*/