config vars are now static
| From: | Monte Ohrt | Date: | Wed, 11 Jun 2003 22:12:53 +0000 |
| Subject: | config vars are now static | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-1546@lists.php.net to get a copy of this message | ||
Hi,
I committed a new behavior into Smarty today. The change is this: when
config vars are compiled, they are written into the template statically
instead of dynamically. That means:
{config_load file="foo.conf"}
{#title#}
Previously this compiled as:
<?php $this->config_load("test.conf", null, 'local'); ?>
<?php echo $this->_config[0]['vars']['title']; ?>
and NOW it compiles as:
MY TITLE
In other words, no PHP logic in the template to spit out a config file
value, the actual value will be in the template.
To accomplish this, some major changes had to be made in the compiling
engine, that is to do it "right". Beware, CVS may not be so stable at
the moment! I tested as much as I could, it cleared the smoke tests but
this affects a lot...
Here is a basic list of concerns and issues I came across:
1) using {config_load ...} in the template has been moved to a compiler
function since it now only executes at compile time. This saves the need
to load config files at runtime. This also means that config file arrays
are no longer cached (not necessary!)
2) The engine now has to differentiate the difference between PHP output
and static output, so a new compiler property $_output_type was added.
Now the compiler can be aware of the output and what to do with it. This
adds a nice flexibility and may prove useful for the future.
3) the config_load API function still exists, but works a bit different
than the compiler method because it executes at runtime, so the function
plugin still exists only for this API. Be aware, using config_load()
from the API may be pretty useless now because it is only needed at
compile time! Use {config_load ...} from within the template if at all
possible so it only executes once. IMHO, this should really be a
function of the template anyways, the app shouldn't have to load configs
into the templates.
4) since templates already recompile when a config file changes,
everything should work OK so long as you have compile_check enabled when
you change something.
I'm sure there are other issues I have not found. Please help test this
if you can, thanks!
Monte