Dynamic Variables
| From: | Stephen J. Lawrence Jr. | Date: | Tue, 31 May 2005 17:30:24 +0000 |
| Subject: | Dynamic Variables | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-12644@lists.php.net to get a copy of this message | ||
Hello, I have a section of template code that needs to be repeated for each value in an array. I would like the variables used in the loop to dynamically change for each iteration. Here is an example of the old code:
<tr>
<td style="text-align: center;">1</td>
<td style="text-align: center;">
<select name="page_key_1_type">
<option value="NULL" >None</option>
<option value="NULL" >------</option>
{foreach from=$command_types item=command_type}
{if $command_type eq $page_obj->page_key_1_type}
{assign var="selected" value="SELECTED"}
{/if}
<option value="{$command_type}" {$selected}>{$command_type}</option>
{assign var="selected" value=""}
{/foreach}
</select>
</td>
<td style="text-align: center;">
<input name="page_key_1_value" value="{$page_obj->page_key_1_value}" size="10" />
</td></tr> Essentially, what I want to do is have an array like this ('1','2','3','4','5','aab','ccd') used to draw this row to the screen, and each iteration would change the '1' in the above example with whichever array value the loop was on. For example: the line that reads "{if $command_type eq $page_obj->page_key_1_type}" would be {if $command_type eq $page_obj->page_key_2_type} on the second iteration, etc,etc.. I need to be able to make the $page_obj->page_key_THISISDYNAMIC_type change each iteration. Any ideas?