Smarty methods for customizing functions in the template engine, Smarty template engine functions
The example of this paper describes the Smarty custom function method, share to everyone for your reference. Specific as follows:
Purpose of this example: Output times con content (output 4 times Hello World)
File 1:
Copy the Code code as follows: <?php
Create a Smarty Object
Require_once ("./libs/smarty.class.php");
$smarty = new Smarty ();
Customizing a function
Description: (1), $arr as an array, (2), TPL invocation form {test times= "4" size= "5" con= "Hello,world" color= "Red"}
function test ($arr) {
$str = "";
for ($i =0; $i < $arr [' Times ']; $i + +) {
$str. = "". $arr [' con ']. "";
}
return $str;
}
Registration function Registerplugin
$smarty->registerplugin ("function", "Test", "test");//The second parameter is the name of the function called by the template file, variable, and the third parameter is the function name defined above; corresponding to a corresponding relationship
$smarty->display ("Temp.tpl");
?>
Template file: Temp.tpl
Copy the Code code as follows:
Smarty Use of custom functions
{Test times= "3" con= "Hello World" size= "3" color= "green"}
Note: Smarty 3.1.8 already does not support the registration function register_function and should be replaced with Registerplugin
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/946748.html www.bkjia.com true http://www.bkjia.com/PHPjc/946748.html techarticle Smarty The method of customizing functions in the template engine, Smarty template engine functions This article describes the Smarty custom function method, share to everyone for your reference. As follows: This example ...