Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Avoid caching of compiler plugin

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jebediah
Smarty Rookie


Joined: 28 Jan 2012
Posts: 16

PostPosted: Fri May 25, 2012 3:59 pm    Post subject: Avoid caching of compiler plugin Reply with quote

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... Sad

Is there any way I can force a compiler plugin NOT to cache?

Thx loads,
Jeb
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat May 26, 2012 10:16 am    Post subject: Reply with quote

You have to use {nocache} tags

Code:
 {nocache}
{do_something what_shall_i_do='show_time'}
{/nocache}
Back to top
View user's profile Send private message
jebediah
Smarty Rookie


Joined: 28 Jan 2012
Posts: 16

PostPosted: Sat May 26, 2012 11:29 am    Post subject: Reply with quote

Hi U.Tews,

thanks loads for your reply.

I've tried that and unfortunately it does not work... Sad

Any other ideas/suggestions?

Thanks,
Jeb
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat May 26, 2012 4:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP