smarty icon indicating copy to clipboard operation
smarty copied to clipboard

Unable to load config in nocache

Open zhuchen115 opened this issue 10 years ago • 1 comments

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.

zhuchen115 avatar May 23 '16 09:05 zhuchen115

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

uwetews avatar May 24 '16 17:05 uwetews