We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Switchee

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi Mark,

I’m glad that you liked my addition of “excise” parameter.

Nesting - it seems somewhat unelegant to have to clone the plugin to get nesting, so I’m not sure about that one. It does suggest another solution - parsing the tag data and inserting aliases for nested tags, then parsing the aliases recursively. I’m going to have a think about it a bit.

Creating a clone of the plugin was quick and dirty solution for enabling to nest {case}{/case} variable pairs. Of course, it would be much better if it were possible to nest them inside the same plugin tag.

BTW, in plugin Find and Replace Plus it is possible to nest {replace_area}{/replace_area} variable pairs.

       
Joe Wolin's avatar
Joe Wolin
206 posts
15 years ago
Joe Wolin's avatar Joe Wolin

@Mark,

Can you think of any other way to process a no_results type output without resorting to an embed? I’m trying to stay clear of embeds to achieve the best performance as I’ve ready it can add a lot of overhead.

thanks…

       
John Tehan's avatar
John Tehan
32 posts
15 years ago
John Tehan's avatar John Tehan

Mark, this looks awesome, I can definitely think of several spots I can use it. But it won’t quite do the trick for the coding issue that made me start looking for something like this in the first place - let me explain.

I’m an old mainframe coder - in Cobol, we have an instruction set that’s similar to switch-case-default, called EVALUATE. It works like this:

EVALUATE (VARIABLE-NAME) WHEN (‘1’) code to execute… WHEN (‘2’) code to execute… . . . WHEN OTHER default code END-EVALUATE.

However, it has one very important difference - it allows me to evaluate the reserved word TRUE, and then check the value of various switches and variables in the WHEN clauses, like this:

EVALUATE TRUE WHEN (SWITCH-1 = ‘Y’ AND SWITCH-2=’Y’ AND STATE = ‘MA’) code to execute… WHEN (SWITCH-1 = ‘Y’ AND SWITCH-2=’Y’ AND STATE NOT = ‘MA’) code to execute… . . . WHEN OTHER default code END-EVALUATE.

The first WHEN clause that returns TRUE gets executed - if none of them return true, the default code gets executed. Can you see any way to make switchee do that? I think it would remove the need for nesting, and be really, really handy. Let me know what you think, thanks!

       
Mark Croxton's avatar
Mark Croxton
319 posts
15 years ago
Mark Croxton's avatar Mark Croxton

Hi John

that’s very interesting. I think it could be possible to add this but what worries me is the AND/OR/NOT logic between evaluated conditions. Currently Switchee effectively only supports OR (using the pipe | separator). Parsing the case values to evaluate the sum of these conditions would be tricky. Having said that, that’s what EE’s if/else advanced conditionals do so there may be code I can borrow there. I’ll look into it.

By the way, if you or anyone else reading this would like to help improve Switchee, I’m now hosting it on Github. Please fork and I’ll happily pull any changes that work well.

       
Interact Marketing's avatar
Interact Marketing
10 posts
12 years ago
Interact Marketing's avatar Interact Marketing

Not able to get it to work with latest EE.

Any clue?

Thanks

       
sheferd's avatar
sheferd
31 posts
11 years ago
sheferd's avatar sheferd

I’m trying to use switchee and for the most part it is doing what I need but I’m stuck with how to implement a regex for “if anything exists here” here is my example:

{exp:switchee variable="{segment_2}/{segment_3}" parse="inward"}
{case value="/"}value{/case}
{case value="value1"}value1{/case}
{case value="value2/#.*#" default="Yes"}default{/case}
{case value="reviews"}reviews{/case}
{/exp:switchee}

The issue is on line 4 above I’ve tried:

#'.*'#
#'^.*'#
#^.*#
#^*#

…etc

with no joy so far any more help is much appreciated, thanks

apologies if this thread was too old to bump /:

Also just a note on getting switch to work… in the past I’ve just dropped the folder ‘croxton-Switchee-b813d5b’ into third_party and it’s worked but lately I’ve had to rename the folder to ‘switchee’ (all lowercase) to get it to show in my plugins manager but in the past doing this made it not work?

       
1 2 3

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.