1

I'm trying to display a matrix field ONLY if it has data entered into it.

I've tried this by wrapping it in this conditional...

{if mymatrix:total_rows > 0}
  {mymatrix}
    data here
  {/mymatrix}
{/if}

But nothing is getting outputted. If I remove the conditional, the matrix is outputted fine. Any ideas? (I'm up to date with EE 2.9.2 & Matrix version 2.6.1)

  • 1
    I've been having some issues with conditionals lately. Does this work? {if "{mymatrix:total_rows}" > 0} – Kieran McClung Dec 22 '14 at 14:44
  • Yup, this worked for me! Thanks! Do you want to add it as an answer and I can mark it as so. Cheers! – shorn Dec 24 '14 at 16:38
3

If you're having trouble with tags not working correctly in conditional statements try wrapping the them in double or single quotation marks.

{if "{mymatrix:total_rows}" > 0}{!-- Here --}
  {mymatrix}
    data here
  {/mymatrix}
{/if}

Thanks :)

| improve this answer | |
0

I had the same issue. This should work for you (it did for me).

{if {mymatrix:total_rows} > 0 }
{mymatrix}
data here
{/mymatrix}
{/if}

Does the template work without the {if} statements? You may also try wrapping the zero in a single quote ( '0' ).

| improve this answer | |
  • Didn't work for me. I get a "This URL cannot be processed" when I tried this. – shorn Dec 21 '14 at 10:14
  • Yes the templates work without the conditionals. The suggestion from Kieran seemed to work fine. Thanks! – shorn Dec 24 '14 at 16:39

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.