[英]Smarty 3 tpl: how to execute php plugin function that calls a smarty variable into the .tpl file?
[英]Error while calling a smarty plugin function from tpl file
使用以下代碼創建了一個簡單的smarty插件
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.assignmenu.php
* Type: function
* Name: assign
* Purpose: assign a value to a template variable
* -------------------------------------------------------------
*/
functionality-to-smarty-w-plugins/
function smarty_function_assignmenu(Smarty_Internal_Template $smarty)
{
//$template->assign($params['var'], $params['value']);
$smarty->assign('test', '123');
}
然后此函數從模板文件中稱為{assignmenu} {test}
訪問頁面時,它將返回以下錯誤參數1傳遞給smarty_function_assignmenu()必須是Smarty_Internal_Template的實例,給定數組,在/var/www/myproject/runtime/Smarty/compile/cda404646b2153274a9e77f736531c5dc7e6f91c_0.file.sample.tpl .php在第31行並已定義
我正在使用yii2的smarty 3。 任何幫助表示贊賞
Smarty插件函數期望將數組作為第一個參數。 所以定義應該是
function smarty_function_assignmenu($paramArray,Smarty_Internal_Template $smarty)
{
$smarty->assign('test', '123');
}
即使沒有要傳遞的參數,函數定義也應包含一個數組作為第一個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.