mehdi mehdi - 8 days ago 6
PHP Question

Smarty cache not working?

I am using Smarty in my projects when I enable caching it doesn't seem to work.
I am using the following structure:


index.php — display(index.tpl)

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

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


In product.php the template product.tpl must loaded in center of index.tpl.
When I enable caching it still shows the default content not product.tpl. When caching is disabled it works fine. What is the problem when caching is enabled?

Answer

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