Re: [SMARTY] Dynamic variables

From: Date: Tue, 29 Apr 2003 12:20:05 +0000
Subject: Re: [SMARTY] Dynamic variables
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9416@lists.php.net to get a copy of this message
On Tue, Apr 29, 2003 at 01:01:37PM +0100, Raul Carvalho wrote: > Hello, > > I have a PHP script that assigns N variables to smarty template, something > like this: > > for ($i=0;$i<N;$i++) { > $var = "sel_$i"; > $smarty->assign($var, $$var); > } > > How do I use these variables in a section or foreach loop? > > To explain my need, consider that "sel_$i" points to an array of values that > will feed the selected attribute of an {html_options} loop. use an 2-dimensional array instead. - fill $sel[$i][$option] - do {html_options options=$sel.$i name="opt[$i]"} if you want the options get passed back, as an array $opts. - if you don't like the backticks, assign a mapping '$i =>"sel[$i]"' from php and use this as name. don't use dynamic varnames in the templates, use (hash-)arrays instead, they can do the same and are far easier. > The idea is to apply the "selected" state to all select elements in a form. > The number of select elements is dynamic, as retrieved from a database. > > Thank you! > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

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