New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Hide content when no results are returned

Madeleine Sharpe May 8, 2019 by Madeleine Sharpe

Hi there, I have a page which displays entries from a particular channel (e.g. entries?path=athletes) under separate headings. These entries are separated into four categories: 1. Runners 2. Sprinters 3. Joggers 4. Walkers

Sometimes there will be no entries for a category but the heading is still displayed on the page. How can I hide the heading if no results are returned for a particular category?

My code is below:

<div class="row">
                                <section id="runners" class="type">
                                        <div class="article-line">
                                                <h3><span>Runners &nbsp;</span></h3>
                                        {{ entries:listing folder="athletes" sort_by="lname" conditions="type:Runners" }}
                                        <section class="athletes-card col-xs-6 col-sm-6 col-md-4 {{ area }} {{name|s                                                                                                                        lugify|trim}}{{ /area }}">
                                                <a href="{{ url }}">
                                                        {{if thumb_image}}
                                                                <img src="{{_image_root}}{{ thumb_image }}" alt="
                                                        {{fname}} {{lname}}">
                                                                <img src="{{ theme:img src="thumb-holder.png" }}" alt                                                                                                                        ="{{fname}} {{lname}}">
                                                        <div class="athlete-text">
                                                                <h4>{{ fname }} {{ lname }}</h4>
                                                                <p>{{ bio|truncate:70 }}</p>
                                        {{ /entries:listing }}
                                        <p class="no-results hidden">No results found.</p>
Answered by Erin Dalzell!
>>>>>>> Answered <<<<<<<
1 Reply
1 Follower