我已經緩存啓用我的Smarty的安裝,並有以下模板函數分配值
function smarty_updatedhour($params, $smarty)
{
$date1 = new DateTime($params['timestamp']);
$date2 = new DateTime("now");
$interval = $date1->diff($date2);
$smarty->assign("updated_period", $interval->format('%h'), true);
}
我已經註冊的插件爲:
$smarty->registerPlugin('function', 'updated_hour', 'smarty_updatedhour', false, array('timestamp'));
我試圖測試它是否是是否工作
{updated_hour timestamp=$timestamp_vale}
{$updated_period}
{if $updated_period > 10}
// do other stuffs
{/if}
但它不起作用,但是當我禁用smarty頁面緩存時, 有用。
誰能告訴我是什麼問題?
好吧,我無法返回函數輸出。這是因爲使用{if} {/ if}在模板上對指定的值進行了進一步處理,並且實際中指定的值不用於在模板內顯示。因此,從您的建議,唯一的可能性是在{nocache}中包裝我的變量輸出(用於測試)或{if}條件。另請注意,我在插件上分配updated_period的同時將nocache設置爲true。 – Prakash 2011-12-20 17:40:57