Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:58:01+00:00 2026-05-27T19:58:01+00:00

I have caching enabled on my smarty installation and have following Template Functions function

  • 0

I have caching enabled on my smarty installation and have following Template Functions

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);
}

I have registered the plugin as:

$smarty->registerPlugin('function', 'updated_hour', 'smarty_updatedhour', false, array('timestamp'));

I tried to test it whether it is working or not

{updated_hour timestamp=$timestamp_vale}
{$updated_period}
{if $updated_period > 10}
    // do other stuffs
{/if}

but it does not work however when I disable the smarty page caching, it works.

can anyone tell me what is the issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:58:01+00:00Added an answer on May 27, 2026 at 7:58 pm

    In Smarty3 your plugins work with the template, not the smarty object. So your function’s footprint is function smarty_updatehour(array $params, Smarty_Internal_Template $template). That’s not your problem, though. Even the assignGlobal() hint by @sudhir won’t help you one bit.

    your non-caching plugin cannot assign variables, but return the actual output:

    function smarty_updatedhour($params, $smarty)
    {
        $date1 = new DateTime($params['timestamp']);
        $date2 = new DateTime("now");
        $interval = $date1->diff($date2);
        return $interval->format('%h');
    }
    

    that is because {$updated_period} is not non-caching. That output is evaluated EXACTLY ONCE and then written to cache. Either try {nocache}{$updated_period}{/nocache} or go with the modified plugin code above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have caching enabled in my smarty and have assigned a date and time
In Yii, I have enabled APC caching through the config/main.php file: 'cache' => array(
In our java/j2ee app we have hibernate and hibernate caching is enabled . But
In particular what strengths does it have over caching features of Asp.net
I have a file caching system for a php application. if a file needs
Since version 1.5 Subversion supports to have a local caching-proxy for the main Master-repository.
I have read the documentation for the CI Caching but still don't understand much
I have read lots of information about page caching and partial page caching in
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
I have a colleague who is looking into opcode caching/Zend Acceleration (I've always assumed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.