0

Matrix 2.5 and 2.6 on ExpressionEngine 2.7.3.

The :total_rows property doesn't work when there are no rows. It works fine when there are rows.

Below isn't actual code, but it's showing the gist.

{exp:channel:entries dynamic="no" channel="regions" url_title="[url_title]"}
    {if "{social_networks:total_rows}" > 0}
        {!--  Do the things --}
    {if:else}
        {!--  Don't do the things --}
    {/if}
{/exp:channel:entries}

Outputting {social_networks:total_rows} is an empty string (which I can't even match against with a conditional) until there's a Matrix row.

Has anyone else noticed this? I don't want to have to start pulling the plugin apart.

1

I believe when there are zero rows the matrix variable just returns false, so you can just use it in the conditional like this.

{exp:channel:entries dynamic="no" channel="regions" url_title="[url_title]"}
    {if social_networks}
        {!--  Do the things --}
    {if:else}
        {!--  Don't do the things --}
    {/if}
{/exp:channel:entries}
2
1

{matrix:total_rows} can't work if there are no rows in the field simply because EE doesn't parse any field tags that don't have any actual data. Matrix never even gets called and the tag gets replaced with nothing.

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.