|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jebediah Smarty Rookie
Joined: 28 Jan 2012 Posts: 16
|
Posted: Fri May 25, 2012 3:59 pm Post subject: Avoid caching of compiler plugin |
|
|
Hello dear community,
I'm using Smarty v.3.1.8 and have written a custom compiler plugin under the name of 'do_something'.
Code: |
function do_something($params, &$compiler){
$smarty = $compiler->smarty;
$what = str_replace( array("'", '"'), '', $params['what_shall_i_do']);
$php = <<EOT
<?php
include_once 'my_functions.php';
do_it('show_time');
?>
EOT;
return $php;
}
|
with the following inclusion from the index.tpl
Code: |
{do_something what_shall_i_do='show_time'}
|
and the following function in my_functions.php
Code: |
function do_it($what_shall_i_do){
if($what_shall_i_do == 'show_time'){
print time();
}
}
|
It's very stupid, I know, but it's for demonstration purposes only.
Smarty is registered the following way:
Code: |
$smarty = new Smarty();
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$smarty->setCompileCheck(false);
$smarty->registerPlugin('compiler', 'do_something', 'do_something', false);
$smarty->display('index.tpl');
|
The problem I have is basically that the index.tpl gets fully cached. So it's displaying the time correctly, but when I refresh it remains at the same time and pulls it from the cache...
Is there any way I can force a compiler plugin NOT to cache?
Thx loads,
Jeb |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat May 26, 2012 10:16 am Post subject: |
|
|
You have to use {nocache} tags
Code: | {nocache}
{do_something what_shall_i_do='show_time'}
{/nocache} |
|
|
Back to top |
|
jebediah Smarty Rookie
Joined: 28 Jan 2012 Posts: 16
|
Posted: Sat May 26, 2012 11:29 am Post subject: |
|
|
Hi U.Tews,
thanks loads for your reply.
I've tried that and unfortunately it does not work...
Any other ideas/suggestions?
Thanks,
Jeb |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat May 26, 2012 4:21 pm Post subject: |
|
|
You did set $smarty->setCompileCheck(false);
In this case Smarty does not recompile the template when you change its source.
During development you should not disable compile checks. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|