I am trying to get a snippet that calculates a value and compare the result to a number - the value is correctly outputted from my snippet when I include the var by itself. However when I use the snippet in a comparison if statement it doesn't work. Here is my code:

{if total-positive-votes > 5} true {/if}

My snippet:

{exp:math_plus calculate="{var2}-({var1} - {var2})" var1="{overall_count}" var2="{overall_sum}"}

Which outputs the following numbers correctly (each comma is a would be comparison):

0, 1, 1, 4, 0, 0, 41, 8 

So my comparison statement should output true on 41 and 8 but nothing comes back. Any one know why this isn't working? The funny thing is it used to work but I didn't use or upgrade this site for 2 years and it broke without me changing anything. Go figure!


If I understood you right, total-positive-votes is your snippet.

I think you're over complicating things, since there's a pack of mathematical operators that can be used on conditionals.

{if overall_sum - (overall_count - overall_sum) > 5}

Or, to keep it even simpler, because multiplications always happen before sum, anyway:

{if 2 * overall_sum - overall_count > 5}
  • I am on version 2.5 - I guess I should upgrade to 2.10 because the new built in operators are bound to help! – Alan Miller May 31 '15 at 2:47

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.