Caching for portals?
| From: | Michal Prinke | Date: | Mon, 15 Apr 2002 19:31:38 +0000 |
| Subject: | Caching for portals? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3751@lists.php.net to get a copy of this message | ||
Monte Ohrt wrote:
>
> There are two different "fetch" functions, and they have different behavior.
> One is in the Smarty API. This gets interpreted as a template:
>
> $smarty->fetch('foo.tpl');
>
> The other is a template function. This is not interpreted, but displayed
> as-is:
>
> {fetch file="/path/to/foo.tpl"}
That's what I meant... I don't think that moving caching logic back to the
PHP script is a good idea - it really should be done in the template itself,
not to bother the person who writes db queries etc.
The way to cache sub-templates which I present below should work, yes,
but it's rather ugly, you must agree:
index.php:
----------
// these sub-templates are pulled from the cache...
$header = $smarty->fetch('header.tpl');
$footer = $smarty->fetch('footer.tpl');
// ...and this are is db-dependent
$smarty->clear_cache('news.tpl');
$smarty->clear_cache('poll.tpl');
$news = $smarty->fetch('news.tpl');
$poll = $smarty->fetch('poll.tpl');
// building the final document
$smarty->clear_cache('index.tpl');
$smarty->assign(array(
"header"=>$header,
"footer"=>$footer,
"news" =>$news,
"pool" =>$pool
));
$smarty->display('index.tpl'); // uufff... that was really ugly...
index.tpl:
----------
<html>
<body>
{$header}
{$news}
{$poll}
{$footer}
</body>
</html>