Page 1 of 1

Caching of Variables Set Within a User-Defined Tag

Posted: Fri Apr 14, 2006 6:07 pm
by ChrisC
I'm trying to set a variable within a user-defined tag so that a later {if} can toggle content.  I've tried using a technique previously posted in the forum; however, the value of the variable gets cached the first time the page is loaded and doesn't get updated unless the page is edited or the cache is cleared.  (This is in 0.12.1.)

Here's a simple example using the time to the second as a value to illustrate the issue.

A tag called {get_date}:

Code: Select all

//$smarty->caching=false;
$d = date("H:i:s");
echo "Inside get_date ($d) <br />";
$smarty->assign($params['var'], $d);
A page that loads it:

Code: Select all

Value before call:({$ret_val})<br />
{get_date var='ret_val'}
Value after call:({$ret_val})<br />
The page results showing the time not being updated come out something like this:
Value before call:()
Inside get_date (10:54:10)
Value after call:(10:53:50)
I tried toggling $smarty->caching, but the results are unpredictable.  On some machines I get the desired behavior, on others I see {nocache} output in the page, and on others the tag gets called twice.

All insight appreciated!

FYI, the actual code I'm trying to debug looks like this:

Code: Select all

$userid = get_userid(false);
$smarty->caching=false;
$smarty->assign($params['var'],(check_permission($userid, $params['name']) ? 1:0));

Re: Caching of Variables Set Within a User-Defined Tag

Posted: Fri Apr 14, 2006 6:09 pm
by calguy1000
try setting the page as non cachable.... that may help.

Re: Caching of Variables Set Within a User-Defined Tag

Posted: Sat Apr 15, 2006 1:23 am
by ChrisC
Oh, yeah, checkboxes.  So much easier than writing code.  Thank you. 

Re: Caching of Variables Set Within a User-Defined Tag

Posted: Thu Jun 01, 2006 8:39 pm
by streever
I am having the same problem, but it hasn't worked for me... any help would be appreciated! (The call to variable is located in the template)

Thanks!
David

Re: Caching of Variables Set Within a User-Defined Tag

Posted: Wed Jun 07, 2006 3:02 am
by calguy1000
The smarty caching stuff was rationalized in 0.13 so it should work there, infact I just tested that tonite, and it seems to work fine.  customcontent variables were getting cached, and it was behaving weirdly.  turning off the checkbox for cachable whilst editing the page fixed the problem.

Re: Caching of Variables Set Within a User-Defined Tag

Posted: Wed Jun 14, 2006 12:36 pm
by peter_parker
in smarty to generate user specific cache use smarty group for the cache page that are generated . Later use validation using if() and for eg

       


if(!$smarty->is_cached('user_page.tpl',"home|".($user->is_user() ? "|".$user->username."loggedin" : "|loggedout")) ) {
                  /* block to write user specific details and then pass it to smarty using smarty-assign() */

}

               $smarty->display('user_page.tpl',"home|".($user->is_user() ? "|".$user->username."loggedin" : "|loggedout"));