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)

2
  • 1
    I've been having some issues with conditionals lately. Does this work? {if "{mymatrix:total_rows}" > 0} Commented Dec 22, 2014 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
    Commented Dec 24, 2014 at 16:38

2 Answers 2

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 :)

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' ).

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

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.