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
Regex Match zero
General
Honcho
|
Posted: 27 May 2014 07:51 AM |
|
|
|
Hello,
I’m using {freebie_3} as the Switchee variable - this can either be blank or a number: 0 to infinity.
The code below works as expected when the the variable is between 1and infinity.
However, when the variable is 0, Case 1 is shown.
I’m assuming Switchee sees blank and ‘0’ as the same?
Could you advise how can I include 0 as a non-blank?
{switchee variable = "{freebie_3}" parse="inward"} {case value=""} Case 1 {/case} {case default="yes"} Case 2 {/case} {/switchee}
Or am I thinking about this wrong…?
Thanks!
|
|
|
Mark Croxton
|
Posted: 08 September 2014 09:04 AM |
# 1
|
|
Developer
|
‘0’ get’s converted to n when passed as a parameter by EE (and 1 is changed to y). Pad your variable with an arbitrary character to force it to remain a string:
{switchee variable = "/{freebie_3}/" parse="inward"}
{!--empty--} {case value="//"} {/case}
{case default="yes"} {/case} {/switchee}
|
|
|