Re: [SMARTY] dynamically creating variable names

From: Date: Tue, 11 Mar 2003 16:46:19 +0000
Subject: Re: [SMARTY] dynamically creating variable names
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8559@lists.php.net to get a copy of this message
> > Do you have any suggestions how to do that? Or how could I create $varName > > before accessing the post-array to have something like > > $smarty.post.$varWithPrefix? > > {assign var=varWithPrefix value="$varPrefix_example"} > {$smarty.post.$varWithPrefix} This is the only possible solution for the moment. Thank you. > but you may want to to something like this in php, before $smarty->display() > > (not tested, but the principle should get clear) > $vars = array(); > foreach ($_POST as $name=>$value) { > if (substr($name, 0, strlen($prefix))==$prefix) > $vars[substr($name, strlen($prefix))] = $value; > } > $smarty->assign('vars', $vars); This doesn't work because the variables are assigned in a smarty template file and not in the php-file. Having something like {$varPrefix_example} would do the trick... Ronino

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