我已经缓存启用我的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