Reputation: 9502
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?
Upvotes: 3
Views: 4702
Reputation: 3483
Before trying to solve smarty caching problem, ie if caching is not happening, please check if your templates_c folder has read and write permissions to all
Upvotes: 0
Reputation: 7956
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}
Upvotes: 0
Reputation: 30083
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
Upvotes: 8