87th Day of Leave PHP smarty template configuration and simple invocation method

Source: Internet
Author: User
Tags smarty template

Configuration file for Smarty templates

<?PHPDefine("ROOT",Str_replace("\\","/",dirname(__file__)).‘ /‘);//constant root Specifies the project root directoryrequireROOT. ' Smarty/smarty.class.php ';//loading the Smarty class file$smarty=NewSmarty ();//instantiating Smarty Objects <br>$smarty->settemplatedir (ROOT. ' Html/');//set all template file storage locations$smarty->setcompiledir (ROOT. ' Html_after/');//set the directory where the compiled template resides$smarty->addpluginsdir (ROOT. ' Plugin/');//set as template extension to store directory$smarty->setcachedir (ROOT. ' cache/');//Set cache file storage directory$smarty->setconfigdir (ROOT. ' config/');//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?>

Citation Method ( Background interface)

<? PHP include". /smarty-ini.php ";           // introducing a configuration file $name= ' John Doe ';                         // Manufacturing Variables $smarty->assign (' name ',$name);        // registering a variable with the smart $smarty->display (' main.html ');        // Mapping template Files

Reference Method ( template interface)

<HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Test</title></Head><Body><!--calling a background variable is displayed in the front end -<{$name}></Body></HTML>

Methods provided by the Smarty template

Loops <{foreach as $i}> <{foreach}>

Structure <{if condition}> <{else If condition}> <{else}> <{/if}>

87th Day of Leave PHP smarty template configuration and simple invocation method

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.