Smarty Template Basics

Source: Internet
Author: User
Tags smarty template

Background isolation, front desk control display, background control content, similar to the CMS principle: User access text.php backstage, background call class smarty.class.php display static template; involves a temporary file a cache file; The principle of core smarty.class.php explains:
<?PHPclasssmarty{ Public $left= "<{";//left delimiter     Public $right= "}>";//Right delimiter     Public $attr=Array();//Store variables//register variables    functionAssign$name,$value)    {        $this->attr[$name]->$value; }    //Show Templates    functionDisplay$filename){        //get static file content        $str=file_get_contents($filename); /**/            //get Results//Regular expression match content, AA, find and replace            /**/            //Get Results//Save the replaced content to a temporary file        $lujing=".. /text/docunment.php "; file_put_contents($lujing,$str); //Read temporary files        include($lujing); }    }

Configuration file int.inc.php (CORE):

<?PHPDefine("ROOT",Str_replace("\\","/",dirname(__file__)).‘ /‘);//constant root Specifies the project root directory//echo str_replace ("\ \", "/", DirName (__file__)). ' /‘; Gets the location of the current filerequireROOT. ' Libs/smarty.class.php ';//loading the Smarty class file$smarty=NewSmarty ();//instantiate Smarty Object//$smarty-auto_literal = false;//You can let the bounding symbol use spaces$smarty->settemplatedir (ROOT. ' Templates/');//set the location of all template files//$smarty->addtemplatedir (ROOT. ' Templates2/'); Add a template folder$smarty->setcompiledir (ROOT. ' Templates_c/');//set the directory where the compiled template resides$smarty->addpluginsdir (ROOT. ' Plugins/');//set as template extension to store directory$smarty->setcachedir (ROOT. ' cache/');//Set cache file storage directory$smarty->setconfigdir (ROOT. ' Configs/');//Setting the template configuration file to store directory$smarty->caching =false;//Setting the smarty cache switch function$smarty->cache_lifetime = 60*60*24;//set the cache template to a valid time of day$smarty->left_delimiter = ' <{';//set the left terminator in the template language$smarty->right_delimiter = '}> ';//set the right terminator in the template language?>

main.php:

<? PHP include (".. /init.inc.php "); $smarty->assign ("AA", "Hello"); $smarty->display ("test.html");

Smarty Template Basics

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.