test.php
<? PHP include ("init.inc.php");
Indexed array $attrArray (1,2,3,4,5); $smarty->assign ("Shuzu",$attr);
Associative arrays
$attr 2 = Array ("A" =>1, "B" =>2, "C" =>3, "D" =>4, "E" =>5);
$smarty->assign ("Shuzu2", $attr 2);
$r = new Ren ();
$smarty->assign ("Ren", $r);//Registered Object
$smarty->assign ("Test", "This is a demo");
$smarty->assign ("Money", 100);
$smarty->assign ("Biaoti", "Fdafdafdsagdasfdasgdafdsagdagds");
$smarty->assign ("BS", 1)
Class Ren
{
Public $name = ' Zhang San ';
}
$smarty->display (test.html);
Test.html
<body>$shuzu[0]} >//take an indexed array
<{config_load file= ' config file name. conf ' section= ' BB '}>//Load profile, section get a block
<div style= "width:200px; height:200px;background-color:<{#bg #}>;font-size:<{#size #}>px "> Test configuration </div>//<{#配置名 #} > or <{$smarty .config.bg}> reserved variables
<{$smarty. Now|date_format: "%y-%m-%d%h:%m:%s"}>//Go to current time return timestamp date_format format string
<{$test |capitalisze}>//variable adjuster format variable name | Adjuster Name Capitalize first letter capital
<{$money |cat: "¥"}>//variable name: Parameter Cat connection string
<{$test |mark}>//Calling custom variables
<{$biaoti |substr:10}>//Call Intercept String custom method
Use if else to pay attention to closure
<{if $bs ==1}>
<div>111111</div>
<{else}>
<div>222222</div>
<{/if}>
foreach Traversal array
<div>
<{foreach $shuzu as $k = $v}>
<div><{$k}><{$v}></div>
<{[email protected]}>//Take an index of an array
<{[email protected]}>//Take iteration count (loop order)
<{[email protected]}>//Determine which is the first data
<{/foreach}>
</div>
</body>
Configuration file
[AA]//block BG=redsize=24[BB]//block BG=yellowsize=36
Custom variable adjuster starts with modifier
Create a new file under the custom plugin directory named modifier. custom file name. PHP Note Naming conventions
<? PHP function smarty_modifier_mark ($str// at least one parameter, which represents the variable itself, takes care of the naming convention { Return "<mark>{$str}</mark>"}
modifier.substr.php
<? PHP function smarty_modifier_substr ($str,$n//$n represents length {$str substr($str, 0,$n-3); return $str. " ...";}
PHP language--smarty variable