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
Implementing Switchee when there’s multiple various and testing
General
jayhlee
|
Posted: 23 October 2014 05:58 AM |
|
|
|
I’m burning some mental fuses trying to figure out how to implement the following situation with Switchee. I’m new to Switchee and am trying to wrap my mind around Switchee in general, but after reviewing the documentations and examples, I still can’t seem to make any progress. Any help would be much appreciated!
{if speaker_facebook != "" OR speaker_twitter != "" OR speaker_linkedin != "" OR speaker_googleplus != "" OR speaker_additional_links != ""} <p class="speaker_links"> {if speaker_facebook != ""} <a href="{speaker_facebook}">Facebook</a> {/if} {if speaker_twitter != ""} <a href="{speaker_twitter}">Twitter</a> {/if} {if speaker_linkedin != ""} <a href="{speaker_linkedin}">LinkedIn</a> {/if} {if speaker_googleplus != ""} <a href="{speaker_googleplus}">Google Plus</a> {/if} {if speaker_additional_links != ""} {speaker_additional_links} <a href="{link_website}">{link_name}</a> {/speaker_additional_links} {/if} </p> {/if}
|
|
|
Mark Croxton
|
Posted: 28 October 2014 12:24 PM |
# 1
|
|
Developer
|
There’s no gain in using Switchee to evaluate multiple variables like this. Switchee implements the switch/case control structure which evaluates a single variable:
http://php.net/manual/en/control-structures.switch.php
Use Switchee when:
* you have a single variable to evaluate, e.g. {segment_2}
* the cases wrap tags that are expensive to run and you only want the matching case to be run
* you need to match a range of possible values with a regular expression e.g. pagination in the form P10, P20 etc)
As of EE 2.9, standard if/else conditionals are evaluated “when ready” by the parser. That means in most (but not all) situations the standard if/else conditionals are all you will need. Conditionals are not parsed *in-between* tags however, read this for more:
https://gist.github.com/croxton/9d012297096892ca5c10
|
|
|