smarty
smarty copied to clipboard
Unable to load config in nocache
if the code was
{foreach $data as $d nocache}
<p>$d</p>
<p>{#SomeConfig#}</p>
{/foreach}
The config can only load on the first time, cannot display when display a cache.
If you need the config variable in cached and nocache sections the simplest is not to use the
{config_load 'foo.conf'}
tag but the Smarty method
$smarty->config_load('foo.conf');
If this is not possible it's a bit more tricky
{config_load 'foo.conf'}
{$foo = true}
{nocache}
{if !isset($foo)}{config_load 'foo.conf'}{/if}
{/nocache}
If the template is not in cache the 1. {config_load 'foo.conf'} will load the config file and $foo gets assigned. If template is in cache the nocache section will be executed and does load the config file as $foo is not assigned