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.
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!
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.
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?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.