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.

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

| improve this answer | |
  • 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. – Kieran McClung Jul 14 '14 at 9:45
  • I made edits to the source in my answer – Johnathan Waters Jul 14 '14 at 10:52
  • So is it still throwing a syntax error? – Johnathan Waters Jul 14 '14 at 10:53
  • Unfortunately so, although it's complaining about the operator now: Parse error: syntax error, unexpected '>' in... – Kieran McClung Jul 14 '14 at 11:04
  • Are the numbers you are comparing with in quotes or not? – Johnathan Waters Jul 14 '14 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}
| improve this answer | |
  • You're still bracing section_1:total_rows, is that intentional? – Derek Jones Jul 15 '14 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. – Kieran McClung Jul 16 '14 at 9:45
  • 1
    Might try 2.9.0 :) – Derek Jones Jul 16 '14 at 14:34

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.