1

We are using Grid to manage resources / and downloads on a site. We need to pull together resources from a number of different entries, based on segment. We use a search within Grid on a Select Dropdown to output the appropriate resource.

This is working as expected, but we cannot find a way to not output the <h2> and <ul> if the search: within Grid has no results. If we use {limit="1"} on {exp:channel_entries} it won't work, as the entry it recalls may or may not have the appropriate resource in the Grid Select Dropdown.

Any help would be much appreciated, thanks.

<h2> Waste Management Group {segment_2}</h2>
<ul class="no-style-list resources">
{exp:channel:entries
    channel="groups"
    disable="categories|member_data|pagination|trackbacks" 
    dynamic="no" 
    status="open"
    cache="yes" 
    refresh="30"
}
{group_resources search:resource_type="{segment_2}"}
    <li>
        <a class="{group_resources:resource_file}{extension}{/group_resources:resource_file} {group_resources:resource_type}" href="{group_resources:resource_link}{group_resources:resource_file}" target="_blank">
            {group_resources:resource_title} {group_resources:resource_file}</a>({exp:filesize_format dec="0"}{file_size}{/exp:filesize_format} {extension}){/group_resources:resource_file}

    </li>
{/group_resources}
{/exp:channel:entries}
</ul>
1

You can use conditionals in the Grid loop to conditionally output the heading and <ul> tags:

{group_resources search:resource_type="{segment_2}"}
{if group_resources:count == 1}
<h2> Waste Management Group {segment_2}</h2>
<ul class="no-style-list resources">
{/if>    
    <li>
        <a class="{group_resources:resource_file}{extension}{/group_resources:resource_file} {group_resources:resource_type}" href="{group_resources:resource_link}{group_resources:resource_file}" target="_blank">
            {group_resources:resource_title} {group_resources:resource_file}</a>({exp:filesize_format dec="0"}{file_size}{/exp:filesize_format} {extension}){/group_resources:resource_file}

    </li>
{if group_resources:count == group_resources:field_total_rows}
</ul>
{/if}
{/group_resources}
3
  • Thx Jeremy. That still outputs the <h2> and <ul> once for each entry that includes at least one row in the Grid. It closes each <ul> for each output as well.
    – Chris
    Feb 13 '14 at 23:12
  • It sounds like what you need is a no_results conditional for the grid field. I'm not sure if that exists. Feb 20 '14 at 20:31
  • Thx Jeremy, I don't think it does. I ended up rebuilding the resources section of the site using Assets.
    – Chris
    Feb 24 '14 at 4:21

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.