PHP代码:
function show_playlist_form($array)
{
global $cbvid;
assign('params',$array);
$playlists = $cbvid->action->get_channel_playlists($array);
assign('playlists',$playlists);
Template('blocks/playlist_form.html');
}HTML代码(内部智能):
<html><head></head>
<body>
{show_playlist_form}
</body>
</html>所有这些都可以在剪辑桶视频脚本中找到。html代码调用php函数,其中显示playlist_form.html.。但是,我感兴趣的是在智能定义的标记show_playlist_form中添加一个整数值,以便将其传递给php show_playlist_form($array)中的函数,然后函数将整数赋值给$array。
我试过了,假设我对传递整数1感兴趣
{show_playlist_form(1)} /home/george/public_html/styles/george/layout/view_channel.html中的致命错误:智能错误:在第4行:语法错误:无法识别的标签: show_playlist_form(1) (Template_Compiler.class.php,第447行)
{show_playlist_form array='1'}html代码起作用了,但我什么也没有得到(空白)。
所以,这不管用,我能做什么?我需要将整数值传递给函数。
发布于 2014-07-23 22:27:04
您在这里要寻找的是实现一个接收参数的“自定义模板函数”。
如关于函数插件的文档所示,您创建的函数将收到两个参数:
因此,例如,如果您定义如下:
function test_smarty_function($params, $smarty) {
return $params['some_parameter'], ' and ', $params['another_parameter'];
}并在Smarty中注册如下所示的名称test:
$template->registerPlugin('function', 'test', 'test_smarty_function');然后您可以在模板中使用它,如下所示:
{test some_parameter=hello another_parameter=goodbye}它的输出应该是:
hello and goodbye在你的例子中,你可能想要这样的东西:
function show_playlist_form($params, $smarty) {
$playlist_id = $params['id'];
// do stuff...
}这是:
{show_playlist_form id=42}https://stackoverflow.com/questions/24921825
复制相似问题