Re: [SMARTY] Use config vars inside .php file (not the .tpl file)
| From: | Tom Henry | Date: | Fri, 14 Mar 2003 02:26:53 +0000 |
| Subject: | Re: [SMARTY] Use config vars inside .php file (not the .tpl file) | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8632@lists.php.net to get a copy of this message | ||
The tip (thanks Monty) to re-read the FAQ lead me to:
A: Yes, using get_template_vars (Oscar Fernandez Sierra):
1. // get all assigned template vars
2. $tpl_vars = $smarty->get_template_vars();
3. // take a look at them
4. var_dump($tpl_vars);
Which lead me to the "intuitively obvious to the least informed" solution
(as is usually the case for us newbies;-)
$cfg_vars = $smarty->get_config_vars();
With the addition of
extract($cfg_vars);
I found that I am saved the necessity of entering 'gets' for each of the vars individually with $foo=$smarty->get_config_vars('foo'), etc
Now it's great to be able to stuff database access and site-wide vars into config files and have them available in the .php files and the .tpl as well.
So the problem is completely resolved (and maybe even understood)
It was encouraging to also learn that it was unnecessary to do anything further -- as all of the {#vars#} we also available in the .tpl file.
A further question comes to mind...
Is there any reason(s) that would make it inadvisable for this to be done automagically any time that a call to either the $smarty->config_load('my.conf') or $smarty->config_load('my.conf','foobar') method is made in the .php files ???
Again thanks to all,
Tom
Monte Ohrt wrote:
get_config_var('foo'), or for a more direct method, FAQ config file section. http://smarty.incutio.com/?page=SmartyFrequentlyAskedQuestions