1

Using assets in a Matrix field, and would like to display 'no results' if a file has not been uploaded for that particular field. Like so...

{exp:channel:entries....etc} {matrix_field} {field_1} {field_2}

{if asset_field}
    {asset_field}
        {url}
    {/asset_field}
{if:else}
    No Files
{/if}

{/matrix_field}

I've tried various combinations of using total_results and changing where the conditional is, complex/simple. Can't seem to find the right combination that works with both cases. Is there a no_results tag? What's the proper way to do this?

2

I just did a quick setup to test. My matrix tag pair is test_matrix. My Assets column is matrix_assets

{exp:channel:entries limit="2"}
<h1>{title}, {entry_id}</h1>
{test_matrix}
{if matrix_assets == ""}nada{/if}
{if matrix_assets != ""}stuff{/if}
{matrix_assets}
{/test_matrix}
{/exp:channel:entries}

I did that with two entries, one with that column populated, one without. This was the output of that template:

testing matrix assets - has no file, 15

nada
testing matrix assets - results, 14

stuff

So you can see the conditionals there are working. Can you give that type of approach a shot?

1
  • I'm not sure what was going on earlier, but that did do it, as it should have!
    – Blair
    Mar 14 '13 at 5:59
1

You can accomplish this one of two ways...

{matrix_field}
{if file}{file}{if:else}no results{/if}
{/matrix_field}

Or, if you're trying to show the "no results" if no matrix rows exist, you could do this...

{matrix_field}
{if total_rows == "0"}no results{/if}
{/matrix_field}

or this...

{if matrix_field == ""}no results{/if}

Let me know if you have questions!

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.