ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Best practices for checking if a channel entries call is empty

May 28, 2011 8:52am

Subscribe [2]
  • #1 / May 28, 2011 8:52am

    Jonas G

    61 posts

    Hi all

    I often find myself with a code block like this

    <div id="calendar"> 
        <a href="http://{path=%27events/index%27}" class="right">See all</a> 
        <h3>Upcoming events</h3><p> <br />
        <ul><br />
            {exp:channel:entries channel="events" sort="asc" show_expired="no" show_future_entries="yes" limit="3" dynamic="off"}<br />
            <li> <br />
                <span class="calendar"> <br />
                    <span class="month">{entry_date format="%M"}</span> <br />
                    <span class="day">{entry_date format="%d"}</span> <br />
                </span> <br />
                <em>{entry_date format="%d. %F %Y"}</em> <br />
                <a href="http://{page_url}">{title}</a> <br />
            </li><br />
            {/exp:channel:entries}<br />
        </ul> <br />
    </div>

    Now if there are no upcoming events, the list is just blank. But if the list is blank I actually don’t want to display anything. What is the best way to achieve that?

  • #2 / May 28, 2011 9:57am

    Rob Sanchez

    335 posts

    {exp:channel:entries channel="events" sort="asc" show_expired="no" show_future_entries="yes" limit="3" dynamic="off"}
    {if no_results}NO UPCOMING EVENTS{/if}
    {if count == 1}
    <div id="calendar"> 
        <a href="http://{path=%27events/index%27}" class="right">See all</a> 
        <h3>Upcoming events</h3><p> <br />
        <ul><br />
    {/if}<br />
            <li> <br />
                <span class="calendar"> <br />
                    <span class="month">{entry_date format="%M"}</span> <br />
                    <span class="day">{entry_date format="%d"}</span> <br />
                </span> <br />
                <em>{entry_date format="%d. %F %Y"}</em> <br />
                <a href="http://{page_url}">{title}</a> <br />
            </li><br />
    {if count == total_results}<br />
        </ul> <br />
    </div> <br />
    {/if}<br />
    {/exp:channel:entries}

  • #3 / May 29, 2011 1:30pm

    Jonas G

    61 posts

    Ah yes. That would work. Thanks for the reply. Would be cool to see other methods of doing this…

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases