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.

Trouble with nested conditional using using custom date field

January 14, 2013 2:44pm

Subscribe [2]
  • #1 / Jan 14, 2013 2:44pm

    mlattis

    1 posts

    Hello.  I am struggling to create a nested conditional that performs different actions depending on whether there are any entries in a channel for which a custom date field value (“events-date”) is in the future.  Here is what I want to accomplish in plain English:

    Step 1. For all events-date > current_time, list event
    Step 2. If no entries exist with events-date > current_time, display “there are no upcoming events”

    Below is the code I have so far, which successfully accomplishes Step 1 above:

    <h3>Upcoming Events</h3>
    <p> {exp:channel:entries status="{env_status}" channel="events" category="not 43" dynamic="no" paginate="bottom"}<br />
      {if events-date > current_time}<br />
       <ul class="news-updates"><br />
        <li>       <br />
         {events-date format="%F %j%S, %Y"}<br />
         <a href="http://{page_url}">{title}</a><br />
        </li><br />
       </ul><br />
      {/if}<br />
     {/exp:channel:entries}

    However, if there are no entries that meet the criteria, the listing will be blank.  What I can’t figure out how to do is display an alternate message if there are no entries with future events-date.  Note that there are many entries in the channel with events-date in the past, so I can’t just do “{if no_results}...” within the exp:channel:entries tag pair.  Logically, it would have to go within the {if events-date > current_time} statement, but that does not work (nothing is displayed).  Here is what I tried, without success:

    <h3>Upcoming Events</h3>
    <p> {exp:channel:entries status="{env_status}" channel="events" category="not 43" dynamic="no" paginate="bottom"}<br />
      {if events-date > current_time}<br />
       {if no_results}<br />
        There are currently no upcoming events scheduled.  To subscribe to email updates, click <a href="/subscribe">here</a>.<br />
       {/if}<br />
       <ul class="news-updates"><br />
        <li>       <br />
         {events-date format="%F %j%S, %Y"}<br />
         <a href="http://{page_url}">{title}</a><br />
        </li><br />
       </ul><br />
      {/if}<br />
     {/exp:channel:entries}

    Alternatively, I wonder if there’s any way to use the “search:field_name=” parameter to filter out events-date values before current_time.

    I hope I’m explaining my issue clearly; I’ll be happy to offer any clarification that is needed.

    Thank you,

    -Michael

  • #2 / Jan 16, 2013 8:27pm

    John St-Amand

    865 posts

    There’s an add-on from Solspace that you might want to have a look at that allows you to work with custom date fields more flexibly - it’s called date field filter. It effectively recaps the native date ordering and sorting functionalities to the custom date field of your choice which then allows you to use if no_results conditionals to do what you’re aiming to do.

    Hope that helps!

  • #3 / Jan 18, 2013 10:26am

    mlattis

    1 posts

    Thank you, John.  That did the trick!

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

ExpressionEngine News!

#eecms, #events, #releases