Home > php教程 > php手册 > Smarty 自定义函数中的传值问题

Smarty 自定义函数中的传值问题

WBOY
Release: 2016-06-06 19:38:10
Original
1066 people have browsed it

Smarty 的 $smarty-registerPlugin()方法自定义函数时,需要将自定义的函数执行以后的结果传值给tpl模板,一直找不到正确的方法。查询Smarty官方文档后,发现只需要在自定义的函数中增加一个$template参数即可实现。 无 function fn_display($_id, $template)

Smarty 的 $smarty->registerPlugin() 方法自定义函数时,需要将自定义的函数执行以后的结果传值给 tpl 模板,一直找不到正确的方法。查询 Smarty 官方文档后,发现只需要在自定义的函数中增加一个 $template 参数即可实现。
function fn_display($_id, $template) {
	$_return = "test";
	$template->assign("display", $_return);
}

$this->obj_smarty = new Smarty(); //初始化 Smarty 对象
$this->obj_smarty->registerPlugin("function", "display", "fn_display"); //注册自定义函数
Copy after login
{call_display call_id=7}

{$display}
Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template