For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > May 2005 > Dynamic Variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Dynamic Variables
Stephen J. Lawrence Jr.

2005-05-31, 4:03 pm

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?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com