Home > Backend Development > PHP Tutorial > How to customize functions in smarty template engine, smarty template engine function_PHP tutorial

How to customize functions in smarty template engine, smarty template engine function_PHP tutorial

WBOY
Release: 2016-07-13 10:09:16
Original
713 people have browsed it

How to customize functions in smarty template engine, smarty template engine function

The example in this article describes the smarty custom function method and is shared with everyone for your reference. The details are as follows:

The purpose of this example: output the content of times con (output hello world 4 times)

File 1:

Copy code The code is as follows:
//Create smarty object
require_once("./libs/Smarty.class.php");
$smarty = new Smarty();
//Customize a function
//Explanation: (1), $arr is an array; (2), tpl calling 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;
}
//Register function registerPlugin
$smarty->registerPlugin("function","test","test");//The second parameter is the function name called by the template file, which is variable; the third parameter is the custom function name above; corresponding to a corresponding relationship

$smarty->display("temp.tpl");
?>

Template file: temp.tpl

Copy code The code is as follows:

Usage of smarty custom functions


{test times="3" con="hello world" size="3" color="green"}

Note: smarty 3.1.8 no longer supports the registration function register_function and should be replaced by registerPlugin

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/946748.htmlTechArticleHow to customize functions in smarty template engine, smarty template engine function This article describes the smarty custom function method in an example, Share it with everyone for your reference. The details are as follows: This example...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template