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}但它不起作用。

有什么建议么?

4

1 回答 1

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 语法)

于 2011-12-19T07:51:17.370 回答