smarty.class.php The main thing in the class
Templates Release Template
Templates_c Cache
Class inside $smarty->assign ("Author", "Feng and Meizi")
$smarty->display ("Test.tpl")
The test.php was looking for a test.tpl file test.tpl:<{$author}>
TEST.TPL file replaces all content after completion
<div><?php echo $this->tpl_vars["author"];? ></div>
There are com_test.tpl.php in the Templates_c file
There is an include () function in test.php that contains the page com_test.tpl.php.
The final display is Feng and Meizi
Configuring Smarty Templates
File directory for Output configuration file
Main file is test.php
Configuration file: init.inc.php
Define Template folder Templates test.html
Define the folder where temporary templates are stored Templates_c
Add template Extensions Store directory plugins
Define cache file storage Directory cache
Define template configuration file storage directory Configs
Custom configuration file configns folder inside the test.conf
system comes with regulator |truncate:5: "..." Requires three parameters: the first parameter is itself, do not write
in the configuration file: $smarty->addpluginsdir (ROOT. plugins/');
The regulator starts with a modifier.
naming rules:
function Smarty_modifiercompiler_lower ($params)
{
if (smarty::$_mbstring) {
return ' Mb_strtolower ('. $params [0]. ‘, \‘‘ . Addslashes (Smarty::$_charset). ' \ ') ';
}
//No mbstring fallback
return ' Strtolower ('. $params [0]. ') ';
}
customizing Plugins 1. Create a new plug-in directory
2. Add plug-in directory $smarty->addpluginsdir (root) in the configuration file. plugins/');
3. New plugin file under directory modifier.mystyle.php
4. Writing Functions
<?php
function Smarty_modifier_mystyle ($str, $color = "Yellow", $size = "20")
{
$str = "<span style= ' color:". $color. "; Font-size: ". $size." PX ' > ". $str." </span> ";
return $str;
}
?>
test.php
<?PHP//Loading initialization filesrequire"Init.inc.php";//Use the Assign () method to insert variables into the template$smarty->assign ("title", "Test page");$smarty->assign ("Content", "contents");$smarty->assign ("Neirong", "This is a test demo");$smarty->assign ("Shuzu",Array("One" =>1, "=>2,3,4,5")));$smarty->assign ("Shijian", Time());@$smarty->assign ("Get",$_get);classren{ Public $name= "Zhang San"; }$ren=NewRen ();$smarty->assign ("Ren",$ren);//Use the display () method in the Smarty object to output the Web page$smarty->display ("test.html");?>
Test.html
<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >$title}></title>$content}><BR/><{$neirong}><BR/><{Print_r($shuzu)}><br/><{$shuzu. one}><br/><{$shuzu. two}><{$ren->name}><{$smarty.get.name}><!--Referencing a custom configuration file--><{config_loadfile= "test.conf" section= "}> <div style=" background-color:<{#bg #}>; width:100px; height:100px; font-size:<{#size #}>px "> Awesome </div></body><!--cat connection string--><div><{$neirong|cat: "Chinese" |cat: "China"}></div><!--intercept English by word, Chinese does not exist in this situation--><div><{$neirong|truncate:6: "}></div><!--so you can intercept English separately--><div><{$neirong|truncate:6:true}></div><!--processing time function--><!--default setting defaults--><!--calling a custom regulator--><div><{$shijian|date_format: "%y-%m-%d%h:%m:%s"}></div><div><{$aa|default: "Hello"}></div><div><{$neirong|mystyle:green:50}></div>init.inc.php
<?PHPDefine("ROOT",Str_replace("\\","/",dirname(__file__)).‘ /‘);//constant root Specifies the project root directoryrequireROOT. ' Libs/smarty.class.php ';//loading the Smarty class file$smarty=NewSmarty ();//instantiating Smarty Objects <br>$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?>
modifier.mystyle.php
<? PHP function smarty_modifier_mystyle ($str,$color= "Yellow",$size= "") "{ $str = "<span style= ' color:". $color. "; Font-size: ". $size. " px ' > '. $str. " </span> "; return $str ;}? >
Test.conf
[ONE]BG=redsize=50[two]bg=yellowsize=24
Php--smarty template (First day)