Reputation:
I have caching enabled in my smarty and have assigned a date and time as below that will only be fetched from database if the page is not cached:
$smarty->assign('added_timestamp', $added_timestamp);
I have a custom smarty modifier that generate a relative period like (20 minutes 5 seconds ago)
{$added_timestamp|relative_time}
now what I need is, the value for '$added_timestamp' must be cached however the output from {$added_timestamp|relative_time}
should not be cached.
I tried with {nocache}{$added_timestamp|relative_time}{/nocache}
but it doesn't work.
any suggestions?
Upvotes: 0
Views: 327
Reputation: 13557
you will need to wrap your relative_time modifier in a function plugin. that function plugin can be registered with the nocache flag (modifiers can't).
$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]);
}
and
{relative_time time=$added_timestamp}
(Smarty3 syntax)
Upvotes: 1