Smarty Configuration and variable adjuster detailed

Source: Internet
Author: User
Tags smarty template

Recently did not do, research and research smarty template engine, more and more feel smarty strong, smarty tutorials on the internet seems to be quite messy.

1. Download Smarty,http://www.smarty.net/download

2. Rename the downloaded Smarty to Smarty and copy to the new folder

3. Create a new smarty.inc.php (or it can be something else)

<?php require_once ' smarty/smarty.class.php ';
$smarty =new smarty ();
$smarty->template_dir= ' templates/';
$smarty->compile_dir= ' templates_c/';
$smarty->cache_dir= ' temp/';
$smarty->config_dir= ' configs/';          $smarty->caching=0;
Cache $smarty->cache_lifetime=60; if (!defined (' Site_url ')) {$url =$_server[' request_scheme ']. ':/
    /'. $_server[' Http_host '];
Define (' Site_url ', $url); } if (!defined (' __root__ ')) {define (' __root__ ', RTrim (DirName (__file__), ' \ \ '). '
\\'); ///Remove backslash if (GET_MAGIC_QUOTES_GPC ()) {function Stripcslashes_arr ($array) {Is_array ($array)? Array_map (' Srtipcs
    Lashes_arr ', $array): Stripcslashes ($array);
                                                                                                                                                                                                                                                  }                                                                                                                          $_post=stripcslashes_arr ($_post);
    $_get=stripcslashes_arr ($_get);
    $_request=stripcslashes_arr ($_request);
    $_cookie=stripcslashes_arr ($_cookie);
$_session=stripcslashes_arr ($_session);
}//Time zone set Date_default_timezone_set (' PRC '); Load function if (file_exists (' common/common.php ')) {require_once ' common/common.php ';}

and manually set up the appropriate directory, debugging, it is recommended to turn off the cache.

And then a new index.php,

<?php
require_once ' smarty.inc.php ';
$title = ' first title ';
$smarty->assign (' title ', $title);
$people =array (
        Array (' name ' => ' John ', ' Sex ' => ' man ', ' age ' => '),
        Array (' name ' => ' Dick ', ' sex ') Male ', ' age ' => '),
        Array (' name ' => ' Harry ', ' Sex ' => ' woman ', ' age ' => '),
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
);
$smarty->assign (' People ', $people);
$smarty->display (' Index.tpl ');

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.