尝试在 smarty foreach 中调用 smarty 插件(带参数)
我正在尝试将个人插件嵌入到我的 smarty TPL 文件中,但我无法使其工作...
这是我的 smarty 插件:
<?php
function smarty_function_alticerik($params, &$smarty) {
if (!function_exists('alticerik')) {
if (!function_exists('get_instance')) return "Can't get CI instance";
$CI= &get_instance();
}
return $CI->IceriklerMod->liste($params['where']);
}
?>
这些是我的 jabber wocky TPL 代码:
{foreach item=alt from=alticerik|@alticerik(where="where ustid=$ustid")}
{$alt.id}
{/foreach}
我已经搜索并阅读了所有 smarty 帮助页面,但我仍然不知道如何使这些代码正确工作......
I'm trying to embed a personal plugin into my smarty TPL files, but I couldn't make it work...
This is my smarty plugin:
<?php
function smarty_function_alticerik($params, &$smarty) {
if (!function_exists('alticerik')) {
if (!function_exists('get_instance')) return "Can't get CI instance";
$CI= &get_instance();
}
return $CI->IceriklerMod->liste($params['where']);
}
?>
And these are my jabber wocky TPL codes:
{foreach item=alt from=alticerik|@alticerik(where="where ustid=$ustid")}
{$alt.id}
{/foreach}
I have searched and read all of the smarty help pages but I still have no idea that how can I make this codes work correctly...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您的问题是函数不会使用 Smarty 语法调用。
您正在做的事情有点像函数和修饰符之间的混合。
修饰符更改给定的输入 - 例如,小写字符串。
函数采用命名参数,通常会做更多的工作,例如创建下拉列表。
就您而言,我猜测您想要使用修饰符,因为您似乎试图修改一个值。您仍然可以将选项传递给它们,但它们没有命名,而且很快就会变得相当混乱。但是,代码可能是:
同时您的实际函数如下所示:
但是请注意,在您的代码中,您最终不会使用模板中 $alticerik 的值,因此这让我想知道您是否需要一个函数。我真的不能确定,除非我明白 alticerik 插件应该做什么。
有关函数和修饰符的更多信息,请参阅此处的文档:Smarty.net 函数文档< /a> 和此处:Smarty.net 修改器文档。
I believe your issue is that functions don't get called using that Smarty syntax.
What you're doing is sort of a mix between a function and a modifier.
Modifiers change a given input - for example, lower casing a string.
Functions take named parameters and usually do a bit more work such as creating a dropdown.
In your case, I'm guessing that you want to use a modifier since you look to be attempting to modify a value. You can still pass options into those, but they aren't named and it gets fairly confusing quickly. However, the code might be:
Meanwhile your actual function looks like:
Note, however, that in your code, you don't end up using the value of $alticerik from your template, so it makes me wonder if you need a function instead. I can't really know for sure unless I get what the alticerik plugin is supposed to do.
For more information on functions and modifiers, see the documentation here: Smarty.net Function Documentation and here: Smarty.net Modifier Documentation.
您的意思是
$CI =& get_instance(); 或许?
什么不起作用?有错误吗?
Do you mean
$CI =& get_instance();
perhaps?and what's not working? Any errors?