1

I've got a weird issue with parentheses in an if statement. If I have the if statement on it's own then no content is shown. If, however, I place two if statements in front of it then everything works fine. See examples below:

Works

{if downloads:total_rows >= '1'}{/if}
{if section_1:total_rows == '1'}{/if}
{if (downloads:total_rows >= '1' || section_2:total_rows == '1') && section_1:total_rows == '1'}
    Content ...
{/if}

Does not work

{if (downloads:total_rows >= '1' || section_2:total_rows == '1') && section_1:total_rows == '1'}
    Content ...
{/if}

Does anyone know why this strange behaviour is occurring?

Thank you.

2 Answers 2

1

I would try putting your variables in curly braces:

{if ({downloads:total_rows} > 0 || {section_2:total_rows} == 1) && {section_1:total_rows} == 1}
    Content ...
{/if}

You are making this an advanced conditional so you can't access your variables correctly in the conditional without the braces. I tested the code above and it works for me.

https://expressionengine.stackexchange.com/a/13946/1188

7
  • For some reason this is now throwing up an error: Parse error: syntax error, unexpected '{' in... Edit: Just noticed that there is a closing curly brace rather than bracket but the error is still appearing. Commented Jul 14, 2014 at 9:45
  • I made edits to the source in my answer Commented Jul 14, 2014 at 10:52
  • So is it still throwing a syntax error? Commented Jul 14, 2014 at 10:53
  • Unfortunately so, although it's complaining about the operator now: Parse error: syntax error, unexpected '>' in... Commented Jul 14, 2014 at 11:04
  • Are the numbers you are comparing with in quotes or not? Commented Jul 14, 2014 at 11:18
1

It seems as though the conditions inside the parentheses don't need the curly braces. At least this has fixed it for me.

{if (downloads:total_rows > 0 || section_2:total_rows == 1) && {section_1:total_rows} == 1}
    Content...
{/if}
3
  • You're still bracing section_1:total_rows, is that intentional? Commented Jul 15, 2014 at 23:04
  • It is intentional however the reason why is confusing me. If I remove the braces then the content does not show, if they're there the content does show. I'm not fully understanding why this is. Commented Jul 16, 2014 at 9:45
  • 1
    Might try 2.9.0 :) Commented Jul 16, 2014 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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