The select="selected" problem

Author Message

Esben Maaløe

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 ?

Esben Maaløe

Monday 23 June 2003 10:52:26 am

Come on - it's an interesting question :)

Björn Dieding@xrow.de

Monday 23 June 2003 9:04:09 pm

Just to give you a rough idea

{let countries=array('Germany','_Norway')
selected='Germany'
}
....
{section loop=$countries}
{switch}
<option value="{$:item}"
{case match=eq($:item,$:selected)}
selected
{case}{/case}
{/swtich}
>{$:item}</option>
{/section}

Looking for a new job? http://www.xrow.com/xrow-GmbH/Jobs
Looking for hosting? http://hostingezpublish.com
-----------------------------------------------------------------------------
GMT +01:00 Hannover, Germany
Web: http://www.xrow.com/

Esben Maaløe

Tuesday 24 June 2003 5:55:09 am

Thanks Björn - that is certainly more elegant.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 16:12:16
Script start
Timing: Jan 18 2025 16:12:16
Module start 'layout'
Timing: Jan 18 2025 16:12:16
Module start 'content'
Timing: Jan 18 2025 16:12:17
Module end 'content'
Timing: Jan 18 2025 16:12:17
Script end

Main resources:

Total runtime0.7449 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 587.9141152.6250
Module start 'layout' 0.00560.0026 740.539139.4453
Module start 'content' 0.00810.7353 779.9844548.2656
Module end 'content' 0.74340.0014 1,328.250012.4766
Script end 0.7449  1,340.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4217160.0002
Check MTime0.00130.1765160.0001
Mysql Total
Database connection0.00070.092410.0007
Mysqli_queries0.695693.3839600.0116
Looping result0.00050.0706580.0000
Template Total0.718796.520.3593
Template load0.00190.257720.0010
Template processing0.716896.220220.3584
Template load and register function0.00010.016510.0001
states
state_id_array0.00080.102310.0008
state_identifier_array0.00070.098720.0004
Override
Cache load0.00170.2216370.0000
Sytem overhead
Fetch class attribute can translate value0.00070.092220.0003
Fetch class attribute name0.00130.180350.0003
XML
Image XML parsing0.00060.074520.0003
class_abstraction
Instantiating content class attribute0.00000.001250.0000
General
dbfile0.00080.1063160.0000
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs