Re: [SMARTY] scoping: php file included by an included template

From: Date: Wed, 06 Aug 2003 15:03:02 +0000
Subject: Re: [SMARTY] scoping: php file included by an included template
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10009@lists.php.net to get a copy of this message
hi, On Wed, Aug 06, 2003 at 04:14:39PM +0200, Paolo Nesti Poggi wrote: > Hi, > > I guess I have a scoping problem. I used a lot of time to track it down but > I couldn't come up with a solution > > In my template I'm including a subtemplate, the subtemplate includes a php > file with {include_php file='includedfile.php'}. > The php file gets it's job done and assignes some values to template > variables. > Everything fine until here. > The problems starts here as I cannot assign values to variables from this > script (doing for instance $extSmarty->assign('var',$output)). > > As you see the script is not just an included script, it is included by an > included template. > I thought I could overcome scoping problems by declaring my extSmarty as > global in each file, however it seems not to be the case. > > The strange thing to me is also that extSmarty from within the script does > work as expected to access paths of templates and the like, so it looks > like it is the same instance of smarty, but variables just don't get > assigned. > > My questions are therefore: > do you know if this case is supposed to work, > do you have any idea of why it doesn't in my case > do you have an idea of what I could have overlooked > do you have any idea of what I could try to come closer to a solution > > I hope really someone can help me 'cause I'm really stucked in this > > Greets > Paolo first: you don't need to globalize $extSmarty. simply do $this->assgin(...) in your included php-files. it may simplify your code a little, but unfortunately that does not solve your problem. i think your problem is that all changes that are done to tpl-vars inside an included template are reverted after the included template is left. it's not a bug of smarty, it's a feature that prevents included templates from overwriting variables from the including template. i think you need another way than assign to get your php-variables out of the included templates.

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