0

I have a matrix field with several columns. When user submits the form I want to display only column fields user entered.

How can I check if matrix field is empty?

Just to clarify I'm talking about expressionengine's Matrix extension.

For example this wont work for me since the row can be submitted empty:

{if "{exercise_set1:total_rows}" >= 1}
{exercise_set1:table cellspacing="0" cellpadding="0" class="format_head"}
{/if}
2
  • What version of EE are you running? Commented Feb 2, 2012 at 14:29
  • I'm curious about the use case. What's the difference to the user between "left the field empty" and "clicked in the field but left it empty"?
    – Mike3d0g
    Commented Feb 2, 2012 at 19:02

2 Answers 2

1

To check if there are any rows filled use

   {if your_matrixfield:total_rows>0}
        {your_matrixfield}
            Do your thing
        {/your_matrixfield}
    {/if}

I had the problem that users could attachs files to an entry but when no files were attached do not generate the Gallery

0

You just want to check to see if anything is set?

{matrix_tagpair}
   {if column_var}{column_var}{/if} 
   OR
   {if column_var != ""}{column_var}{/if}
{/matrix_tagpair}
2
  • Is it possible to do something like this: {exercise_set1} {if exercise != ""} {exercise_set1:table cellspacing="0" cellpadding="0" class="format_head"} {/if} {/exercise_set1} Commented Feb 2, 2012 at 14:40
  • 1
    No - the table tag does not allow for that. However you could do something like: {exercise_set1:table cellspacing="0" cellpadding="0" class="format_head" search:exercise="key word"} Since we don't know what your variables contain data wise it will be hard say for sure what will work. Be sure to read pixelandtonic.com/matrix/docs/templates Commented Feb 2, 2012 at 15:27

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.