Re: AW: [SMARTY] Cache and insert second time..
| From: | Monte Ohrt | Date: | Wed, 05 Feb 2003 22:20:01 +0000 |
| Subject: | Re: AW: [SMARTY] Cache and insert second time.. | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7537@lists.php.net to get a copy of this message | ||
Changes committed to CVS, see if that works for you.
Monte
On Wed, 2003-02-05 at 15:07, Rainer Collet wrote:
> > We've gone that approach before, something like this:
> >
> > {insert name="get_banner" template="banner.tpl"}
> >
> > Then the insert function does its db query then does:
> >
> > return $this->fetch('banner.tpl');
> >
> > ... displaying the results. This way the insert content is still
> > maintained in a template.
>
> And this is the way caching wont work any longer. I did not try it with
> 2.4.0 already, but afaik this part of the source did not change since 2.3.0.
> I already posted this several times, but no one responsed.
>
> Try the following:
>
> index.php
> ------------------
> require_once ( "Smarty.class.php" );
> $smarty = new Smarty;
> $smarty->caching = 1;
> $smarty->cache_lifetime = 30;
> $smarty->display ( "insert.tpl" );
> ------------------
>
> plugins/insert.test.php
> ------------------
> function smarty_insert_test($params, &$smarty)
> {
> extract $params;
> return $text;
> }
> ------------------
>
> plugins/function.test.php
> ------------------
> function smarty_function_test($params, &$smarty)
> {
> //$cache_info = $smarty->_cache_info;
> $smarty->display("test.tpl");
> //$smarty->_cache_info = $cache_info;
> }
> ------------------
> test.tpl
> ------------------
> TEST
> ------------------
>
> insert.tpl
> ------------------
> {insert name="test" text="TEST"}<br>
> {test}<br>
> ------------------
>
> You'll get pretty errors. Uncomment the two lines in insert.test.php and it
> will work.
> This is because of the $_cache_info variable in smarty. First, this variable
> will be ok, but then the call to $smarty->display in smarty_function_test
> will reset $_cache_info['insert_tags'] so that the generated
> cache/insert.tpl.php will get a wrong cache header viz without the
> information in $_cache_info['insert_tags'].
>
> So on the next execution of insert.php the insert_cache tag in the cached
> file will not be evaluated, because of the missing
> $_cache_info['insert_tags'] information in the cache header.
>
> I also posted a patch on the SMARTY-DEV mailling list against 2.3.0 wich
> works for me. Here it is again:
>
> 609a610,611
> > if (isset($this->_cache_info)) $_cache_info = $this->_cache_info;
> >
> 658a661
> > if (isset($_cache_info)) $this->_cache_info = $_cache_info;
> 661a665
> > if (isset($_cache_info)) $this->_cache_info = $_cache_info;
> 705a710,711
>
>
>
>
> >
> > if (isset($_cache_info)) $this->_cache_info = $_cache_info;
> >
> > Monte
> >
> > On Wed, 2003-02-05 at 12:45, Nino Katic wrote:
> > > Hi,
> > >
> > > I didn't get the right answer last time I asked this, so maybe this time
> > > I'll be luckier :-)
> > > So, my question is this: If I use insert with the function that
> > access db
> > > and gets some data from it am I supposed to define my html
> > layout in that
> > > function? For example, if db query returns 10 columns which I store in
> > > arrays and then i use it on different positions on my page I'm
> > not able to
> > > define layout in smarty template because it has been cached?
> > The only part
> > > that was not cached is that insert function, so I suppose I
> > should define
> > > html layout in it. Is this right?
> > >
> > > Nino
> > --
> > Monte Ohrt <monte@ispi.net>
> >
> >
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
--
Monte Ohrt <monte@ispi.net>