Smarty environment Configuration and use introduction tutorial _php instance

Source: Internet
Author: User
Tags php template smarty template

This article describes the Smarty environment configuration and use method. Share to everyone for your reference, specific as follows:

Download Smarty (take Smarty-2.6.26 here for example). Unzip the downloaded file (the directory structure is quite complex). Next, I will show you an example of installation, which should be extrapolate.

(1) A new directory learn/was established in the root directory, and a directory smarty/was established in learn/. The libs/copy of the directory that you just unzipped into the smarty/, and then in smarty/new Templates directory, templates in 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:

<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01
 
 

To create a new index.php, place this file under learn/:

<?php
require ' 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 caching, if this is true, open caching, but will cause the Web page is not immediately updated problem, of course, can also be resolved by other means to resolve
$smarty->caching = false;
$smarty->left_delimiter = "{#";//redefine the boundary, because the default boundary "{}" character, the "{}" character is used to embed the JS script file in the HTML page, the custom boundary character can also be <{}>
$smarty->right_delimiter = "#}";
$hello = "Hello world!"; /Assignment
$smarty->assign ("Hello", $hello);//reference template file
$smarty->display (' Index.tpl ');? >

(3) The executive index.php will be able to see Hello world!.

For more information about PHP interested readers can view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP Array" Operation Techniques Encyclopedia, "PHP based on PDO Operation Database Skills summary", "PHP Operations and Operator Usage Summary" , "PHP Network Programming Skills Summary", "PHP basic grammar Getting Started", "PHP object-oriented Program Design Primer", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on Smarty template.

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.