Smarty tutorial-smarty getting started basic application instance tutorial

Source: Internet
Author: User
Tags mysql tutorial smarty template

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.

*/

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.