Re: [SMARTY] Accessing Assigned Variables

From: Date: Fri, 31 Jan 2003 21:56:46 +0000
Subject: Re: [SMARTY] Accessing Assigned Variables
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7445@lists.php.net to get a copy of this message
On 31 Jan 2003 at 13:14, Darryl Bleau wrote: > > I think you misunderstand what I want to do. > > there is no '$var1' in my PHP. If you read closely, I assigned like this: > > $smarty->assign("var1","data"); > > Just to make sure I wasn't on drugs, I tried what you said and of > course, got back: > > Notice: Undefined variable: var1 in xxx.php on line xxx > > As I mentioned, I can do this by accessing $smarty->_tpl_vars['var1'] > but I thought there was a cleaner way. I'm so stupid! Sorry, you're right - I totally misunderstood you. Somehow I thought you wanted to know how to access smarty variables from within templates - although the example was PHP- code: if (...) instead of {if ...}. Currently there is only one clean but circuitous way to access assigned Smarty vars in PHP scripts: $vars = $smarty->get_template_vars(); if ($vars['var1'] == 'data') { // ... } Generally, one should avoid such situations by finishing all logic before assigning smarty vars or even before creating the smarty object. Sorry for the inconvenience!!! -- Ferdinand Beyer <fbeyer@clickhand.de>

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