1. Follow the original system main program, data, function library, interface, etc., change it does not affect the whole. is essentially a function.
2. Plug-in common type: functions function Plug-in
modifiers modifier plug-in (variable adjuster plugin)
Block functions block Function plugin
3. Create and use plugins:
(1) Use the Registerplugin method to register the written plugin.
(2) Put the plug-in into the plugins directory in the Lib directory of the Smarty extract directory
(3) PHP built-in functions, can be directly used in the template as a variable adjuster.
Definition and use of three common plug-ins
Functions function Plugin:
Define the file in Lib/plugins function.test.php
function Smarty_function_test ($params) {//smarty_function_ plug-in name
$width = $params [' width ']; $params receive Array (parameter 1=> parameter value, parameter 2=> parameter value);
$height = $params [' height '];
$area = $width * $height;
return $area;
}
Called in the template file:
{Test width=200 height=100}
modifier plug-in (variable adjuster plug-in):
Define the file in Lib/plugins modifier.test.php
function Smarty_modifier_test ($utime, $format) {//smarty_modifer_ plug-in name
Return Date ($format, $utime);
}
PHP File: $smarty->assign (' Time ', Time ());
Called in the template file:
{Time | test: "Y-m-d h:i:s"}
Block Plugin (block functions plugin):
Define the file in Lib/plugins block.test.php
function Smarty_block_test ($params, $content) {//smarty_block_ plug-in name
$replace = $params [' Replace '];
$maxnum = $params [' maxnum];
if ($replace = = ' true ') {
$content = Str_replace (', ', ', ', $content);
$content = Str_replace ('. ', '. ', $content);
}
$content = Sub_str ($content, ' 0 ', $maxnum);
return $content;
}
PHP File: $smarty->assign (' str ', "hello,my name is Lilei. How is it? ");
Called in the template file:
{Test replace= ' true ' maxnum=20}
{$STR}
{/test}
Smarty Base Plug-in