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
Numbers as Values Not Working
Support Request
brianrivet
|
Posted: 15 December 2015 09:53 PM |
|
|
|
Hi,
I’m trying to use Switchee in conjunction with the Yahoo Weather plugin to show custom icons based on the value returned by the condition code from the weather plugin. For some reason, my default catch all case is firing even though I have a case that should match the code. I am thinking I just have something written incorrectly but I’m not sure what. I was hoping you could help me resolve. Here’s my code:
{exp:switchee variable = "{current_condition_code}" parse="inward"}
{case value="0|1|2|23|24"} <span class="icon-wind"></span> {current_condition_temp_c}° {/case} {case value="3|4|37|38|39|45|47"} <span class="icon-lightning2"></span> {current_condition_temp_c}° {/case} {case value="5|6|7|8|10|13|14|17|18|35|42|46"} <span class="icon-weather4"></span> {current_condition_temp_c}° {/case} {case value="15|16|41"} <span class="icon-snowy3"></span> {current_condition_temp_c}° {/case} {case value="9|11|12"} <span class="icon-rainy2"></span> {current_condition_temp_c}° {/case} {case value="19|20|21|22"} <span class="icon-windy"></span> {current_condition_temp_c}° {/case} {case value="25"} <span class="icon-snowflake"></span> {current_condition_temp_c}° {/case} {case value="26"} <span class="icon-cloudy2"></span> {current_condition_temp_c}° {/case} {case value="27|29"} <span class="icon-cloud"></span> {current_condition_temp_c}° {/case} {case value="28|30|44"} <span class="icon-cloudy"></span> {current_condition_temp_c}° {/case} {case value="31|33"} <span class="icon-moon"></span> {current_condition_temp_c}° {/case} {case value="33"} <span class="icon-moon"></span> {current_condition_temp_c}° {/case} {case value="32|34|36"} <span class="icon-sun"></span> {current_condition_temp_c}° {/case} {case default="yes"} <!-- {current_condition_code} -->{current_condition_temp_c}° {/case} {/exp:switchee}
When I run it is showing the default case, but in the comment it shows a code from the weather plugin of 33, which I have a case for. Can you tell me what I’m doing wrong?
Thanks,
Brian
|
|
|
brianrivet
|
Posted: 20 December 2015 10:22 AM |
# 1
|
|
|
Has anyone got any ideas on this? I tried not having multiple values in the same case statement but that didn’t do anything either.
Thanks!
Brian
|
|
|
Mark Croxton
|
Posted: 21 December 2015 02:59 PM |
# 2
|
|
Developer
|
In older versions of EE, parameters containing a ‘1’ or a ‘0’ would get converted to ‘Yes’ and ‘No’ respectively, and this is then passed to Switchee. In the latest version ‘0’ gets converted to ‘’.
So if you are evaluating ‘0’ or ‘1’ exactly you will need to pad the value with an arbitrary character, e.g ‘@’
So:
{exp:switchee variable = "@{current_condition_code}@" parse="inward" debug="yes"}
{case value="@0@|@1@|@2@|@23@|@24@"} <span class="icon-wind"></span> {current_condition_temp_c}° {/case}
The only other issue I can spot is you have two cases that match ‘33’.
|
|
|