Re: [SMARTY] array in config file

From: Date: Wed, 26 Feb 2003 15:18:05 +0000
Subject: Re: [SMARTY] array in config file
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8223@lists.php.net to get a copy of this message
index.php --------- $smarty->config_overwrite = false; $smarty->display('index.tpl'); display.conf ------------ test1 = one test1 = two test1 = three index.tpl --------- {config_load file="display.conf"} {* #test1# is now an array *} On Wed, 2003-02-26 at 07:22, Martin Kloss wrote: > Hi everyone, > > I'm trying to figure out how to store an array in a config file. > For example in a config file 'my.conf' I have: > > test1 = array('one', 'two', 'three') > test2 = "one, two, three" > test3 = 'one', 'two', 'three' > > loading the file with > > $smarty->config_load('my.conf'); > > makes them accessible in my templates, which works just fine. > But if I try to use the array for a popup menu in a form, I always > get a string no matter which variation I try: > > <SELECT NAME=subject> > {html_options options=#test1# selected=$selection} > </SELECT> > > I would split the string into an array, like so: > > $options = split(',', $test2); > $site->assign('options', $options); > > but I can't seem to get to the config var "test2" in PHP !? On the > template, accessing it with {#test2#} works fine. though. > > I have currently solved the problem with the following workaround, > which is not very elegant and doubles the load, since I'm also > doing a "$smarty->config_load('my.conf')" to have the config vars > globally accessible: > > $conf = new Config_File; > $conf->get('my.conf'); > $options = eval('return(' . $conf['test1'] . ');' ); > $site->assign('options', $options); > > Then the following works: > > <SELECT NAME=subject> > {html_options options=$options selected=$selection} > </SELECT> > > So this raises two questions: > > 1. How can I access config vars loaded with "$smarty->config_load()" in a > PHP script? > 2. How can I store an array in a config file and use it in a template as an > array ? > (currently all I get is a string, no matter how I format it) > > Tia, > Martin. > > > Martin Kloss > > Need music? http://www.selling-sound.com > > Like the author? Buy the book at: > http://www.amazon.de/exec/obidos/ASIN/3898422194/lingmmugd > > Get your daily dose of Lingo at the LingoPark: > http://www.lingopark.com > -- Monte Ohrt <monte@ispi.net>

« previous php.smarty.general (#8223) next »