Sunday 22 June 2003 7:15:17 am
I just made something that needed a select box. The select box should be able to default to a certain value. I had to do it this way:
<option value="Afghanistan" {switch match=$selected_option}{case match='Afghanistan'}selected="selected"{/case}{/switch}>Afghanistan</option>
<option value="Albania" {switch match=$selected_option}{case match='Albania'}selected="selected"{/case}{/switch}>Albania</option> <option value="Algeria" {switch match=$selected_option}{case match='Algeria'}selected="selected"{/case}{/switch}>Algeria</option> In my case that gives more than 200 switch statements that I have to execute. I'd much prefer something like
{ let $$selected_option='selected="selected"' }
<option value="Afghanistan" {$Afghanistan}>Afghanistan</option>
<option value="Albania" {$Albania}>Albania</option>
<option value="Algeria" {$Algeria}>Algeria</option> {/let} Where $$selected_option works just like in PHP - a variable variablename. Will the template language support variable variablenames in the future? How could I have made my select box thing smarter ?
|