2

I'm trying to use MX Calculate to perform a percentage calculation of each row in a matrix column and the percentage is based on the value that's in each row which I'm trying to get Switchee to recognize but I think my problem lies somewhere in the parse order but I can't figure it out. Here's the code:

{exp:switchee variable="{event_fee}" parse="inward"}

     {case value=">=1000"}
     <strong>
     $ {exp:mx_calc parse="inward" expression="{event_fee}/100*40"}
     </strong>
     {/case}

     {case value="<=999"}
     <strong>
     $ {exp:mx_calc parse="inward" expression="{event_fee}/100*30"}
     </strong>
     {/case}

 {/exp:switchee}

Thanks.

  • What is {event_fee} and what is {fee}? – Jason Varga Mar 19 '13 at 13:34
  • Hi Jason. I'm sorry I made a correction the {fee} was suppose to be {event_fee}. The {event_fee} is a number field within matrix. – Azul Mar 19 '13 at 13:45
  • just a side note, this works perfectly fine: $ {exp:mx_calc parse="inward" expression="{event_fee}/100*40"} it's only when using Switchee there's no output. – Azul Mar 19 '13 at 13:48
1

According to a forum post on Devot:ee, you can't do less thans or greater thans inside the case values.
You'll need to use a regular expression.

http://www.regular-expressions.info/numericranges.html explains how to define numeric ranges.

But for your example, case value="#^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$#" should match 0-999. (Your regex needs to be enclosed with hashes).

If you are only using the two cases you mention, you might be better off using IfElse. I'm pretty sure you can use greater than and less than.

| improve this answer | |
0

In this instance you'd probably be better off using Ifelse rather than Switchee. While you can certainly bodge all sorts of things with regular expressions, a switch statement isn't generally the way to go if you just want a simple n < y check.

{exp:ifelse parse="inward"} 
    {if event_fee < 1000}
        <strong>
        $ {exp:mx_calc parse="inward" expression="{event_fee}/100*30"}
        </strong>
    {if:else}
         <strong>
         $ {exp:mx_calc parse="inward" expression="{event_fee}/100*40"}
         </strong>
    {/if}
{/exp:ifelse}

The ifelse plugin will remove non-matching conditions before they're parsed, so you'll still only have one mx_calc call per row.

Edit: I've just noticed Jason's mentioned ifelse in his response already. I'll leave my answer here since the sample code might be useful.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.