views:

656

answers:

2

i used smarty in my projects when i enable caching it’s not working . because i use this structure :

index.php — display(index.tpl)

index.tpl —- {include file=$page_center}

?module=product — $smarty->assign(”page_center” , “product.tpl”) ;

ok ?

i’m in product.php so poduct.tpl must load in center of index.tpl . when i enable caching it’s still show default content not product.tpl ! when it’s disabled it’s working

what’s the problem ? how can i solve that ?! sorry about my bad english .

+2  A: 

You will need to use a unique cache ID for each page to make this work correctly:

$cacheID = 'some_unique_value_for_this_page';
$smarty->assign('page_center', 'product.tpl');
$smarty->display('index.tpl', $cacheID);

Given the example you gave in the question, it could make sense to use the module name from your query string as the basis for the cache ID.

There's more information about in the Smarty manual: http://www.smarty.net/manual/en/api.display.php

georgebrock
ok . i test it but it's dosen't help me unfortunately beacause every time a module calls a new cach file is created in cach directory , it's same as i use $smarty->force_compile . this is way is not correct way to catching i think .
mehdi
A: 

you need create an dynamic module!

function smarty_block_dynamic($param, $content, &$smarty) {
    return $content;
}

then

$smarty = new Smarty
$smarty->register_block('dynamic',
                        'smarty_block_dynamic',
                        false /* this block wont be cached */);

and your tpl

Hello {$name}

this is your las update

{/dyamic}
{include file="some/dynamic/thing.tpl"}
{/dynamic}
Gabriel Sosa