Re: [SMARTY] Re: global vars in templates
| From: | Monte Ohrt | Date: | Mon, 15 Apr 2002 14:34:11 +0000 |
| Subject: | Re: [SMARTY] Re: global vars in templates | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3731@lists.php.net to get a copy of this message | ||
When you created the $a variable, you were not in global scope (just in the scope of the current Smarty template.) You could do this:
$GLOBALS['a'] = 'foo';
myfunc() {
echo $GLOBALS['a'];} Then you know your variable is always in global scope. Norbert Röcher wrote:
"Eric" <eric@themepark.com> schrieb:-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.The variable $a is not carried down into the function test_a, eventhough Iuse the 'global' command. (It works fine, of course, if I justinclude thefile in PHP file for the page, instead of trying to have the templatedo theinclude.) Why does this happen? Does it have something to do with variablescopingaround classes?Yes. This should work like you expect: <?php global $a; $a = 123; test_a(); function test_a() { global $a; if ($a == 123) { echo "yeah it works!"; } else { echo "no luck-- bummer dude"; } } ?> Regards, Norbert