2

how can I conditionally output rows of an matrix, if there are any? Eg:

{if matrixfield}
    <h2>Also check</h2>
    {matrixfield}
        <a href="{url_title}">{title}</a><br />
    {/matrixfield}
{/if}

Thanks!

10

Yep, just check to see if the matrix field total_rows are greater than 0

{if my_matrix_field:total_rows > 0}
    Matrix field has rows
{/if}
1
  • This should be marked as the answer, IMHO. – Nick Benson Oct 21 '13 at 20:38
3

I dont have enough rep to make a comment.

So, I am not sure what you are looking for. The code below is an example how to work with conditionals for Matrix.

{matrixfield}

   {if no_results}
       No rows available
   {/if}

   {if '{row_count}' == '1'}
       <a href="{url_title}">{title} - First row</a>
   {/if}

  <a href="{url_title}">{title}</a>

   {if '{row_count}' == '{total_rows}'}
        <a href="{url_title}">{title} - Last row</a>
   {/if}
{/matrixfield}

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.