Smarty environment configuration and use Getting Started tutorial php smarty mescaline Lai Smarty Assign

Source: Internet
Author: User
Tags php template smarty template
In this paper, we describe the Smarty environment configuration and usage method. Share to everyone for your reference, as follows:

Download Smarty (take Smarty-2.6.26 for example). Unzip the downloaded file (the directory structure is quite complex). Next, we will show you an installation example and see that it should be extrapolate.

(1) Create a new directory in the root directory learn/, and then create a directory smarty/in the learn/. The libs/copy of the directory just extracted to smarty/, and then in smarty/new Templates directory, templates new cache/,templates/,templates_c/, config/.

(2) Create a new template file: Index.tpl, put this file in the Learn/smarty/templates/templates directory, the code is as follows:

 
  
<?phprequire ' smarty/libs/smarty.class.php '; $smarty = new smarty;//Sets the path of each directory, here is the focus of the installation $smarty->template_dir = " Smarty/templates/templates "; $smarty->compile_dir =" Smarty/templates/templates_c "; $smarty->config_dir =" Smarty/templates/config "; $smarty->cache_dir =" Smarty/templates/cache ";//smarty template has the function of cache, If this is true then open the caching, but will cause the page does not immediately update the problem, of course, can also be resolved by other means $smarty->caching = false; $smarty->left_delimiter = "{#"; Redefine the boundary, because the default boundary "{}" character, the HTML page embedded in the JS script file to write code snippets using the "{}" character, custom boundary character can also be <{}>, {//} etc $smarty->right_delimiter = "# } "; $hello =" Hello world! "; /Assignment $smarty->assign ("Hello", $hello);//reference template file $smarty->display (' Index.tpl ');? >

(3) Execute index.php to see Hello world!.

More interested in PHP related content readers can view the topic: "Smarty Template Primer Basic Tutorial", "PHP Template Technology Summary", "PHP array" operation Skills Daquan, "PHP based PDO operation Database Tips summary", "PHP Operations and Operator Usage Summary" , "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP Object-oriented Programming tutorial", "PHP String Usage Summary", "Php+mysql Database Operation Primer" and "PHP common database Operation Skills Summary"

It is hoped that this article will be helpful to everyone based on smarty template PHP program design.

The above describes the Smarty environment configuration and use of the introductory tutorial, including the smarty aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.