Re: [SMARTY] global vars in a php block

From: Date: Tue, 16 Dec 2003 18:39:51 +0000
Subject: Re: [SMARTY] global vars in a php block
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10705@lists.php.net to get a copy of this message
Jason Hubble ha scritto:
I assume you have a good reason for doing this and the more traditional way of doing this wouldn't work. If that is the case, here is something to try: {php} global $MYVAR; echo "Printing from php<br>"; echo "\$MYVAR: $MYVAR"; {/php} The way of doing this that would make more since to me would be like this: $MYVAR = "test"; $smarty = new Smarty; $smarty->assign('MYVAR',$MYVAR); $smarty->display('index.tpl'); Having a index.tpl like this: Print from php<br> $MYVAR: {$MYVAR}
Hi Jason, thank you for your suggestion, which is perfect but I cannot use it for my purposes. I just simplified too much, asking how to reach global vars from a php block. My prob is that I use only one php *index.php* which display a smarty template require_once "common.inc"; $smarty = new Smarty; $smarty->display('index.tpl'); This one will build the main part of every pages, which will be different only for an include. e.g. <html header> {include file="$myFile"} <html footer> The value of $myFile will be different compared to params coming from the query part used why flashing index.php e.g. index.php?f=first will include first.inc
     index.php?f=second will include second.inc
Now... I use a conf file [e.g. common.inc] in which I set all the general global php vars I need, for example db params. I already include this file in *index.php* because I need it just to assign some vars to smarty. The point is that... the content of every inclusion will be different obviously, and sometimes I need to use a {php} block, for example to read a db table or to include a whole php file which could use any of the global vars contained in common.inc As far as I can see I have only 2 ways: 1. require common.inc anytime I need in a php block or php file to be included in the main template. 2. use extract($GLOBALS) in place of the previous require to make any global vars reachable. I was just wondering if there's something wiser, something like a boolean smarty param similar to $request_use_auto_globals. Hope it makes sense Luca

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