Setting the value of variables in a switch statement

Author Message

joe hobbs

Monday 04 July 2005 3:29:17 am

Hello
I am using a drop down menu to allow a visitor to search for facilities in a region. Much of the solution to that was kindly provided by members of the eZ community on these boards. Now I want to modify the feature further. To achieve that I using a 'switch' statement which is in a html form. It seems simple enough, but I am not having any success. I suspect it is something to do with using a switch to set the value of a variable. I include the code and I wonder if any one could point me in the right direction? Incidently, if the switch statement were successful I would pass the value by method = 'get' to a template file to be used as an argument in a fetch.
As usual many thanks for your good attention.

{*I want to set the value of app depending on the page_ID*}
{let pageid=$node.node_id}
{let app=' '}
{switch name=pagetester match=$pageid}
{case match=72}
$app='petrol'
{/case}
{case match=71}
$app='pubs'
{/case}
{case}
default case
{/case}
{/switch}

Eivind Marienborg

Monday 04 July 2005 5:28:02 am

You have to use set-tags, like this:

{*I want to set the value of app depending on the page_ID*}
{let pageid=$node.node_id
            app=' '}
{switch name=pagetester match=$pageid}
{case match=72}
{set $app='petrol'}
{/case}
{case match=71}
{set $app='pubs'}
{/case}
{case}
default case
{/case}
{/switch}
{/let}

Also, it's a good thing to make it a habit to close your let's :)

joe hobbs

Monday 04 July 2005 6:35:59 am

Thank you Eivind
I edited the code with your suggestion (below). Unfortunately the value of the variable 'app' does not get reset to 'edu' in the switch and retains the initial value, 'test' when I output it. Logic tells me this should work, but what is missing?

{let pageid=$node.node_id app='test'}
{switch name=pagetester match=$pageid}
{case match=73}
        {set $app='edu'}
{/case}
{case}
        default
{/case}
{/switch}
{/let}

Eivind Marienborg

Monday 04 July 2005 6:45:50 am

Hmm, sorry, I can't seem to find any errors in your code there.. Anyone else?

Trevor Clowry

Wednesday 06 July 2005 8:05:18 am

I've had the same problem as this on several occasions and can't find the solution.
In a similar example to Joe Hobbs version I have tested the node_id before the switch statement. When the node id is equal to 73 it enters the case:

{case match=73}
        {set $app='edu'}
{/case}

However when i test the $app variable after the switch statement it is still set to its original value. It seems like the $app variable is not being set.
Can somebody try joe's code in a template file and see if it works?
Can anyone suggest a workaround to this?
Thanks again.
Trevor

joe hobbs

Friday 08 July 2005 8:27:39 am

To conclude on this post. I used an if statement to resolve the problem I experienced with the switch (see code below). If anyone knows why the switch would not set the value of the variable whereas the if statement will I would be most interested to learn.
Many thanks

{let pageid=$node.node_id app=''}
{if eq( $pageid, 73 )}
    {set $app='edu'}
{else}
    {set $app='default'}
{/if}


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 31 2025 05:32:25
Script start
Timing: Jan 31 2025 05:32:25
Module start 'layout'
Timing: Jan 31 2025 05:32:25
Module start 'content'
Timing: Jan 31 2025 05:32:26
Module end 'content'
Timing: Jan 31 2025 05:32:26
Script end

Main resources:

Total runtime1.0820 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 588.2813151.2266
Module start 'layout' 0.00660.0025 739.507836.6797
Module start 'content' 0.00911.0721 776.18751,000.1328
Module end 'content' 1.08120.0008 1,776.320315.8125
Script end 1.0819  1,792.1328 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3157160.0002
Check MTime0.00140.1284160.0001
Mysql Total
Database connection0.00110.104010.0011
Mysqli_queries1.020794.3382680.0150
Looping result0.00060.0575660.0000
Template Total1.044396.520.5221
Template load0.00200.184320.0010
Template processing1.042296.328320.5211
Template load and register function0.00130.119110.0013
states
state_id_array0.00190.175510.0019
state_identifier_array0.00110.098320.0005
Override
Cache load0.00160.1512320.0001
Sytem overhead
Fetch class attribute can translate value0.00080.078330.0003
Fetch class attribute name0.00180.163570.0003
XML
Image XML parsing0.00230.215730.0008
class_abstraction
Instantiating content class attribute0.00000.001380.0000
General
dbfile0.00330.3023160.0002
String conversion0.00000.000740.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
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/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: 28
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs