Share » Forums » Developer » Bug in switch statement?

Bug in switch statement?

Bug in switch statement?

Monday 30 January 2006 9:04:03 am - 5 replies

Modified on Tuesday 31 January 2006 7:37:41 am by Trygve Fridstrøm

Author Message

André R.

Monday 13 February 2006 8:33:01 am

tried changing the switch statment to if statment ??

...
           {set CourseTypeID= ... something ...} 
           --> {$ListCourseTypesID.0} and {$CourseTypeID} are equal here <-- 
           {if eq($CourseTypeID , $ListCourseTypesID)}
                   -->Never enters here <-- 
                   {node_view_gui view=listitem content_node=$course} 
           {/if} 
....

Either way you don't need a switch when there is only one case.

EDIT: section actually loops, see documentation:
http://ez.no/products/ez_publish_open_source_enterprise_cms/documentation/reference/template_functions/program_flow/section

so you'll have to loop thru the $ListCourseTypesID array (a loop in a loop..)

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Trygve Fridstrøm

Tuesday 14 February 2006 1:16:52 am

Thanks for your reply.

The reason I used switch was that it's easy to check if the match variable value exists in an array (see documentation of switch statement):
{switch match=$CourseTypeID}
{case in=$ListCourseTypesID}

I can't use an if-statement to compare $CourseTypeID and $ListCourseTypesID since one is an array and the other is a single value.

Section doesen't loop unless one uses loop=... in the section definition.

Trygve Fridstrøm

Tuesday 14 February 2006 1:23:07 am

Besides, I would like to avoid using the section statement, since it's not so easy to read and also deprecated according to the documentation.

André R.

Wednesday 15 February 2006 3:14:57 pm

Ok,

but you'll have to change
{if gt($ListCourseTypesID|count(),0)}
to a loop as this line
{section show=$ListCourseTypesID}
makes the code loop thru $ListCourseTypesID

either a new 'foreach' or 'for'

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Hans Melis

Wednesday 15 February 2006 11:40:25 pm

André,

A section does not loop unless the "loop" parameter has been specified. Only using the "show" parameter makes it a conditional statement. The old documentation is not always right. Anyways, section has been deprecated as of 3.6 and the new control/looping structures should be used.

Trygve,

You can use an if statement instead of a switch to compare the string and the array. Your switch construct checks if a $CourseTypeID is in the $ListCourseTypesID array. This can be done in a more elegant way with an if statement:

{if $ListCourseTypesID|contains( $CourseTypeID )}

Why the switch doesn't work when inside an if-block is not clear to me without trying it. But try the if I mentioned to see if that alleviates the problem.

Hans
http://blog.hansmelis.be

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu