Caching of Variables Set Within a User-Defined Tag

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
ChrisC

Caching of Variables Set Within a User-Defined Tag

Post 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));
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post by calguy1000 »

try setting the page as non cachable.... that may help.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
ChrisC

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

Post by ChrisC »

Oh, yeah, checkboxes.  So much easier than writing code.  Thank you. 
streever

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

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
peter_parker

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

Post 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"));
Post Reply

Return to “Developers Discussion”