Re: [SMARTY] global vars in a php block

From: Date: Tue, 16 Dec 2003 17:34:27 +0000
Subject: Re: [SMARTY] global vars in a php block
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10704@lists.php.net to get a copy of this message
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} Luca Borrione <spatuss@hotpop.com> wrote: > Hi, > > my question is stupid but I would like to know > the best way to solve it. > > Having a index.php like this: > > $MYVAR = "test"; > $smarty = new Smarty; > $smarty->display('index.tpl'); > > > Having a index.tpl like this: > {php} > echo "Printing from php<br>"; > echo "\$MYVAR: $MYVAR"; > {/php} > > I would like to obtain: > Printing from php > $MYVAR: test > > Unluckly $MYVAR is not reachable from the php block. > I solved it using > {php} > extract($GLOBALS); > echo "Printing from php<br>"; > echo "\$MYVAR: $MYVAR"; > {/php} > > but I don't like this solution. > Is there any better way? > > Thank you in advance, > Luca

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