|
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 |
metheorn Smarty Rookie
Joined: 22 Aug 2003 Posts: 14
|
Posted: Thu Oct 30, 2003 3:18 pm Post subject: Fonctionnement du cache |
|
|
Bonjour,
J'utilise Smarty de la façon suivante : inclusion de templates dans des templates
exemples :
1.tpl
{include "a.tpl"}
{include "b.tpl"}
2.tpl
{include "a.tpl"}
{include "c.tpl"}
Dans mon code PHP, j'effectue un display uniquement des tempates génériques:
$smarty->display('1.tpl');
ou $smarty->display('2.tpl');
Dans ce cas, comment mettre le template a.tpl en cache sachant que je ne fait pas de display de ce template directement.
Merci |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Oct 31, 2003 1:40 am Post subject: |
|
|
I'm not sure I get you right, but you want to ensure you have a cached copy of template 'a' for calls from '1' and '2'?
If so, pre-fetch your template 'a' so that a cache image is built. Cache images are for calls to display/fetch and are not on the "per" template basis, as you might expect. Assuming you having caching turned on: eg.
$result = $smarty->fetch('a.tpl'); // creates cached image of a.tpl
$smarty->display('1.tpl');
On the otherhand, just leaving it as it is will cause a compiled version of your 'a' and 'b' templates to be generated, even if they are not called via display/fetch.
HTH |
|
Back to top |
|
metheorn Smarty Rookie
Joined: 22 Aug 2003 Posts: 14
|
Posted: Fri Oct 31, 2003 11:10 am Post subject: |
|
|
It dont't seems to work ...
Just see the example below.
index.php:
Code: | include("global.php"); ---> initialisation of smarty and DB Access
$smarty->caching = 2;
include("inc_menu.php"); ----> Menu from DB table
$smarty->cache_lifetime = 300;
$result = $smarty->fetch('inc_header.tpl'); ------> Generate a cache of inc_header.tpl
$smarty->display('index.tpl'); |
index.tpl
Code: | {include file="inc_header.tpl"} -----> Standard header for all the templates
{include file="inc_menu.tpl"} ----> Display the menu and the time |
If you put time in inc_header.tpl, it will be refresh every 15 minutes.
In the other hand, if you put $smarty->cache_lifetime = 0; before the display(), it will refresh the menu AND the header |
|
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
|