2011-12-19 46 views
0

我已经缓存启用了我的智者,并已经指定日期和时间如下,将只从数据库中读取如果页面没有被缓存:缓存Smarty的值,但不会修改器输出

$smarty->assign('added_timestamp', $added_timestamp); 

我有一个自定义Smarty的修改产生像(20分5秒前)一个相对周期

{$added_timestamp|relative_time} 

我现在需要的是,对于“$ added_timestamp”值必须然而缓存从{$added_timestamp|relative_time}输出不应该被缓存。我试过{nocache}{$added_timestamp|relative_time}{/nocache}但它不起作用。

有什么建议吗?

回答

1

您将需要将您的relative_time修饰符包装在函数插件中。该函数插件可以注册nocache标志(修饰符不能)。

$smarty->registerPlugin('function', 'relative_time' 'smarty_function_relative_time', false, array('time')); 
function smarty_function_relative_time(array $params, Smarty_Internal_Template $template) { 
    $template->smarty->loadPlugin('smarty_modifier_relative_time'); 
    return smarty_modifier_relative_time($params[time]); 
} 

{relative_time time=$added_timestamp} 

(Smarty3语法)