1

Trying to check if all the last two fields are empty in all rows in a grid.

Right now code is checking each row:

{if page_minutes_table:total_rows > 0}
    <table>
        <thead>
            <tr>
                <th>Meeting Name</td>
                <th>Minutes</td>
                {if page_minutes_table:document_2 != "" && page_minutes_table:document_3 != ""}
                <th colspan="2">Additional Documents</td>
                {/if}
            </tr>
        </thead>
        <tbody>
        {page_minutes_table}
            <tr>
                <td>{page_minutes_table:meeting_name}</td>
                <td>{if page_minutes_table:minutes_document}<a href="{page_minutes_table:minutes_document}" target="_blank">Download Minutes</a>{if:else}coming soon{/if}</td>
                {if page_minutes_table:document_2 != "" && page_minutes_table:document_3 != ""}
                    <td>{page_minutes_table:document_2}</td>
                    <td>{page_minutes_table:document_3}</td>
                {/if}
            </tr>
        {/page_minutes_table}
        </tbody>
    </table>
{/if}
1

Not 100% sure I understand what you are trying to do - in your example code you appear to want to display all entries in the grid field, and have a heading included if there are downloadable documents available for an entry. The only way to do this is to loop through every row in the grid field.

I think you are asking if there is a way to get the information about how many rows in the table don't have either document_2 or document_3 defined without having to loop through all the entries. One way would be to use the search:column_name parameter in your grid tags.

The search:column_name parameter limits the results generated by a tag to just those entries within the entire (in this case grid) field that meet the criteria. This is helpful where you only want to work with a subset of entries, but here you could use it just to flush out a total_rows count for the search - thusly:

{page_minutes_table search:document_2="not IS_EMPTY" search:document_3="not IS_EMPTY"}
   {if page_minutes_table:total_rows}There are {page_minutes_table:total_rows} entries that have both{/if}
{/page_minutes_table}

HTH

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.