Plugin

Archived
Forum
(read-only)

Switchee

ExpressionEngine 1.x, ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Switchee and low_events, unexpected result

Support Request

Rick Lecoat
Rick Lecoat

I have a template that displays an event for which the date and date are set using the low_events add-on. I’m trying to use Switchee to test whether the event has been flagged as ‘all_day’—the variable to test is thus {events_datetime:all_day}. The event in question does have the ‘all_day’ flag set, but whilst a regular EE conditional picks up on that, Switchee seems not to. Here is my template test code:

{if events_datetime:all_day == "y"}
 EE CONDITIONAL REPORTS TRUE
<br>
{/if}
{exp
:switchee variable "{events_datetime:all_day}" parse="inward"}
    {case value
="y"}
        SWITCHEE REPORTS TRUE
    {
/case}
    {case value
="" default="Yes"}
        SWITCHEE REPORTS FALSE
    {
/case}
{
/exp:switchee} 

I would expect both the EE conditional and Switchee to both report TRUE, but the template’s output is:

EE CONDITIONAL REPORTS TRUE
SWITCHEE REPORTS FALSE 

Why are the two methods giving different returns? Is it a parse order issue? And if so, is there a way around it?

Mark Croxton
# 1
Developer
Mark Croxton

This isn’t valid:

{case value="" default="Yes"}
        SWITCHEE REPORTS FALSE
    {
/case} 

Should be

{case default="yes"}
        SWITCHEE REPORTS FALSE
    {
/case} 

Also, EE converts some values that it considers might be true/false booleans when passed as a parameter or evaluated in conditionals. Try surrounding with the shim character to mainatain it’s real value, e.g.

{exp:switchee variable "@{events_datetime:all_day}@" parse="inward"}
    {case value
="@y@"}
        SWITCHEE REPORTS TRUE
    {
/case}
    {case 
default="yes"}
        SWITCHEE REPORTS FALSE
    {
/case}
{
/exp:switchee} 

Add debug=“1” to Switchee to see what value it is really evaluating in the template debug output.

 

Rick Lecoat
# 2
Rick Lecoat

Thanks Mark. The change to the default option syntax didn’t make any difference (though it’s good to know the correct syntax for future reference), but adding in the shim character did. That’s not something I think I would have ever discovered on my own, so many thanks.