[prev in list] [next in list] [prev in thread] [next in thread] 

List:       smarty-dev
Subject:    Re: [SMARTY-DEV] assign inside a 3rd level included template
From:       "Jimmy Harlindong" <jimmy () harlindong ! com>
Date:       2003-06-24 10:54:29
[Download RAW message or body]

> On Tue, Jun 24, 2003 at 07:26:16PM +1000, Jimmy Harlindong wrote:
> > > On Tue, Jun 24, 2003 at 06:02:52PM +1000, Jimmy Harlindong wrote:
> > > > I have a global template:
> > > > 
> > > > <html><head>{$head}</head><body>{$body}</body></html>
> > > > 
> > > > then in my php:
> > > > 
> > > > // need to use this since body.tpl is actually a variable.
> > > > $smarty->assign('body', $smarty->fetch('body.tpl'));
> > > > $smarty->display('theabovetemplate.tpl');
> > > > 
> > > > in body.tpl I have:
> > > > 
> > > > {include file="sub-body.tpl"}
> > > > 
> > > > and in sub-body.tpl:
> > > > 
> > > > {assign var="head" value="xxxx"}
> > > > 
> > > > Apparently this assignment to "head" variable inside sub-body.tpl doesn't \
> > > > reach to the global template (I got empty <head></head> in the output). If I \
> > > > move this assign smarty function to body.tpl it will work and show up in the \
> > > > global template  
> > > > Is this a bug or by design? 
> > > 
> > > it's by design. :)
> > 
> > Care to explain why?
> 
> hmm i'm not 100% sure, it was not my design :)
> 
> i think the scope of the variable-changes inside an included template
> is local, mainly to prevent any side-effects caused by that template
> *accidently*. it's a pity for you, that you want these side-effects
> *intentionally*.
> 
> but i'm sure there are far better explanations for this behaviour.> 

Thanks for the explanation. I had a look at the compiled template:

<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include("sub-body.tpl", array());
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

So smarty restores the _tpl_vars that was saved prior to the inclusion. Hmmm need to \
find an approved way to do this.




-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic