Re: [SMARTY] Accessing variables inside {php} sections

From: Date: Mon, 12 Jan 2004 23:45:55 +0000
Subject: Re: [SMARTY] Accessing variables inside {php} sections
References: 1 2 3  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10817@lists.php.net to get a copy of this message
Francesco Cipriani wrote:
On Mon, Jan 12, 2004 at 11:15:36PM +0100, messju mohr wrote:
what is the solution? How can I access assigned variables from php sections in smarty's templates?
the included php runs in the context of a method of your smarty instance: you can use: $program = $this->get_template_vars('program);
Thank you. Maybe it would be nice to have this included in the manual, {php} section. It seems to me that the variables' scope inside templates isn't well specified. Suppose I want to use in a smarty tag a variable just declared in a php sectin, what it the right way to do this? I mean, something like {php} $var = 'hello'; {/php} {$var (or_what_else??)}
In the {php} section, use $this->assign() or $this->assign_by_ref() as you would do on the smarty object before disp[laying the template. You are within a member function of the smarty class, so you can use any of its funcitons with $this. -- paperCrane <Justin Patrin>Question Everything, Reject Nothing

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