EE 1
EE 2
Switchee
Developer
3rd Party (Free)
Compatibility
- LG Addon Updater
- Multi Site Manager
- Stand Alone Entry Form
Requirements
- jQuery for the Control Panel
- Hermes
A very simple plugin that allows you to create switch/case control logic in your templates.
With EEs if/else conditionals, each condition is parsed before being removed at the end of the parsing process. This means if you wrap if/else tags around lots of other tags then your template will be running many unnecessary queries and functions.
As Switchee is a tag we can use parse=“inward” to ensure that unmatched conditions are not parsed before being removed from the template.
Switchee can only be used for simple conditional logic. Like PHPs switch/case, it supports a default value.
Example:
{exp:switchee variable = "{variable_to_test}" parse="inward"}
{case value="value1"}
Content to show
{/case}
{case value="value2" default="Yes"}
Content to show
{/case}
{case value="value3"}
Content to show
{/case}
{/exp:switchee}
Note that ‘default’ can also be used on it’s own:
{case default="Yes"}
In some of my templates I’ve seen a 30% decrease in queries by using Switchee in preference to if/else.
Download Switchee
| EE Version | Downloads | Add-On Version | Release Date |
|---|---|---|---|
| 2.+ | Download | 06/28/2010 |
Switchee Links
- [EE Forums] Forum thread
This entry was last updated September 1, 2010, 12:02 pm.
Disclaimer: Information about ExpressionEngine add-ons is provided as a service to you, the user, and every member of the ExpressionEngine community. Devot:ee is not responsible if you hose, mangle, wreck, or otherwise destroy your EE website by installing an add-on that you found out about at this site, regardless of its rating, Favorites status, commercial or free status, or general popularity. Caveat EEmptor!


2 Reviews:
Ryan Masuga 09.01.10
I frequently use a single template to do various things (list of entries, single-entry page and more) and Switchee allows me to do this knowing that we won’t have a lot of unnecessary queries running for non-matching cases.
Much better and cleaner than using simple conditionals. Nice work.
Jacob Russell 09.01.10
Great way to get around the problems with EE complex if statements parsing their contents early, which can put a major load on pages. Also useful for situations where Case makes more sense then If/Else, obviously.