1

I've got a compound Matrix/tabular data/conditional situation I'm trying to figure out. I have a table displaying a matrix of credits for various people with columns for Year, Project, Role and Awards. In several cases a particular person may always have the same Role. In a some cases a particular person may have no awards. In each case, that Role and/or Awards column is unnecessary. I would like to use a conditional statement that will:

  1. Determine if all the entries of the Role column are the same and if so, hide that column including the column header.
  2. Determine if all the entries of the Awards column are empty, and if so, hide that column including the column header.

I can write a conditional on an entry by entry basis to exclude the table cell if it is empty, but that doesn't remove the column, even if they're all empty, because the header is still hard coded.

I've looked into using Stash, https://github.com/croxton/Stash#expstashset_list-tag-pair but wanted to know if there was a simpler method.

This is an example of a page where both the Role and Awards columns would be hidden. http://toddao.css-staging.com/talent_detail/joe-barnett

Here is the simplified code

{exp:channel:entries channel="creative_talent" dynamic="yes" limit="1"}
        <table>
        <tr><th colspan=4>Selected Credits</th></tr>
        <tr>
        <th>Year</th>
        <th>Project</th>
        <th>Role</th>
        <th>Awards/Nominations</th>
        </tr>
        {credits}
        <tr>
        <td>{Year}</td>
        <td>{Project}</td>
        <td>{Role}</td>
        <td>{Awards}</td>
        </tr>
        {/credits}
        </table>
{/exp:channel:entries}

Any advice would be appreciated.

Thanks

1

The item number 2 can be done using the exp:channel:entries and an embed:

{embed="template_group/.table" has_awards="{exp:channel:entries channel='creative_talent' limit='1'}{credits search:awards='not IS_EMPTY' limit='1'}yes{/credits}{/exp:channel:entries}"}

Sadly, this doesn't work for number 1. So, I used query module for both. In my sample code, roles are on col_id_26 and awards are on col_id_25. Just replace by the IDs you need.

{embed="template_group/.table"

    multiple_roles="{exp:query sql='SELECT row_id FROM exp_channel_titles
    JOIN exp_matrix_data ON exp_channel_titles.entry_id = exp_matrix_data.entry_id
    WHERE url_title = '{segment_2}'
    AND col_id_26 != ''
    GROUP BY col_id_26
    LIMIT 2' limit='2'}{total_results}{/exp:query}"

    has_awards="{exp:query sql='SELECT row_id FROM exp_channel_titles
    JOIN exp_matrix_data ON exp_channel_titles.entry_id = exp_matrix_data.entry_id
    WHERE url_title = '{segment_2}'
    AND col_id_25 != ''
    LIMIT 1'}yes{/exp:query}"
}

I used row_id just to get something from the query.

On your embed:

{exp:channel:entries channel="creative_talent" limit="1"}
    <table>
        <tr>
            <th colspan="{if "{embed:has_awards}" AND "{embed:multiple_roles}"}4{if:elseif "{embed:has_awards}" OR "{embed:multiple_roles}"}3{if:else}2{/if}">Selected Credits</th>
        </tr>
        <tr>
            <th>Year</th>
            <th>Project</th>
            {if {embed:multiple_roles} > 1}<th>Role</th>{/if}
            {if "{embed:has_awards}"}<th>Awards/Nominations</th>{/if}
        </tr>
        {credits}
            <tr>
                <td>{Year}</td>
                <td>{Project}</td>
                {if {embed:multiple_roles} > 1}<td>{Role}</td>{/if}
                {if "{embed:has_awards}"}<td>{Awards}</td>{/if}
            </tr>
        {/credits}
        </table>
{/exp:channel:entries}

It Isn't a simple answer, but your need isn't simple either.

| improve this answer | |
  • Thank you, Robson. I like how you saw I need to adjust the colspan on the first th. I was so focused on the other parts I missed that! I will give it a try and let you know. – Tom Loveman May 28 '13 at 22:09

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.