Re: [SMARTY] Dynamic Variables
| From: | Stephen J. Lawrence Jr. | Date: | Tue, 31 May 2005 20:39:07 +0000 |
| Subject: | Re: [SMARTY] Dynamic Variables | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12645@lists.php.net to get a copy of this message | ||
Well, I have 12 different sets of variables on this page that I display in a form. The html is all identical except for the variable names. I am trying to keep from having to hardcode 12 different HTML TR's for each of the vars.
On the PHP side, I have done this:
$this->digits = array('1','2','3','4','5','6','7','8','9','0','aa','bb','cc');
foreach($this->digits as $digit)
{
$type_varname = 'page_key_' . $digit. '_type';
$this->{$type_varname} = $rs->fields['page_key_' . $digit . '_type'];
}
Then I want a foreach in the template to spin through each of the variables.
{foreach from=digits item=$digit}
<input name="page_key_{$digit}_value" value="{$page_obj->page_key_$DIGIT_value}" size="10" />
{/foreach}
the "name=page_key_{$digit}_value" part works fine, but the "value=" part does not. The first loopthrough, the value needs to be $page_obj->page_key_1_value, the second through needs to be $page_obj->page_key_2_value, etc..
steve
Bill Cunningham wrote:
Stephen, That was a much clearer explaination of what you're looking for. It appears that perhaps you want an array there. Something like: $my_obj->var[$cnt] ?? What about: $var = "variable_1_value"; $my_obj->$$var ?? <<- not sure if a variable indirection works in a template though. Maybe it would help if you told us exactly why you are trying to achieve this. Are you trying to auto create a bunch of templates? - Bill