Answers.Body: <p>When you are setting <code>nextEvent</code>, you can limit only events that are upcoming and only output the first result you get back like so:</p>
  
  <pre><code>.startDate('&gt;= ' ~ now).first()
  </code></pre>
  
  <p>So you can take that and update your code like so:</p>
  
  <pre><code>{% set nextEvent = craft.entries.section('events').order('startDate').startDate('&gt;= ' ~ now).first() %}
  
  {% if nextEvent %}
      foo
  {% endif %}
  </code></pre>
  
  <p>I have assumed you have a section called 'Event's until we get some clarification as to what <code>craft.events.events</code> is.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T12:27:34.053Z
Answers.Text: That was fast enough, Jamie! Congrats. ;) I'd suggest to use `first` method instead of setting a limit, though.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T12:35:22.553Z
Answers.Text: The code won't work as I'm using the Craft events plugin. {% set nextEvent = craft.entries.events.order('startDate').startDate('>= ' ~ now).limit(1) %} is trowing in an SQL state error (column not found)
Answers.UserDisplayName: Robbie Post
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T13:42:53.943Z
Answers.Text: @RobbiePost Hi Robbie, please have a look at the answer posted by carlcs. The code I supplied will work, but you will need to make some adjustments to how you handle events, as that plugin shouldn't be used in production sites.
Answers.UserDisplayName: Jamie Wade
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T12:22:40.180Z
Answers.LastActivityDate: 2015-05-06T12:34:32.827Z
Answers.LastEditDate: 2015-05-06T12:34:32.827Z
Answers.UserDisplayName: Jamie Wade
Answers.Body: <p>P&amp;T's events plugin available on GitHub <a href="http://github.com/pixelandtonic/Events" rel="nofollow">http://github.com/pixelandtonic/Events</a> is actually not meant to be used at all. It was just a demo to show the potential of custom element types!</p>
  
  <p>I'd suggest to use a channel section for your events, and with the code Jamie provided you're already done figuring out how to find your "next event"! You could also collect events with a matrix field, if you have a need for an extra level of hierarchy and if that's still not enough you could have your events in a table in that matrix (using the <a href="https://github.com/engram-design/SuperTable" rel="nofollow">"Super Table"</a> plugin).</p>
  
  <p>There's also two other plugins: <a href="https://github.com/tippingmedia/craft.events" rel="nofollow">"Events"</a> and <a href="http://michaelrog.com/craft/calendars/introduction" rel="nofollow">"Calendar"</a>, but I'm not sure if they are still under development and I'd probably stick to core Craft features (channels / matrix) for now.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T13:41:32.837Z
Answers.Text: Thanks for clarifying carlcs. I agree, the P&T plugin is a no-go and a channel would be the best option for this.
Answers.UserDisplayName: Jamie Wade
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T14:13:42.060Z
Answers.Text: For me events plugin was a quick and simple solution for a simple project. I solved the issue by hiding the generated list in HTML and only showing the first-child. Thanks for the suggestions
Answers.UserDisplayName: Robbie Post
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T14:28:12.023Z
Answers.Text: There's a better way to do this, @Robbie. I just posted another answer, but please do me a favor and don't accept it. Using P&T plugin is indeed a no-go ...
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-07T06:20:48.833Z
Answers.Text: The breakloop suggestion did the job and solved the issue. It's clear now that the P&T events plugin is not the way to go
Answers.UserDisplayName: Robbie Post
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T13:15:14.970Z
Answers.LastActivityDate: 2015-05-06T13:15:14.970Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>To break a for loop you could have a variable and check against its value in your loop:</p>
  
  <pre><code>{% set breakLoop = false %}
  
  {% for entry in nextEvent %}
  
      {% if (entry.startDate &gt; now) and (breakLoop == false) %}
          {{ entry.startDate }}
          {% set breakLoop = true %}
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
  <p>Or – if you have a need to break loops more often – use the plugin <a href="https://github.com/marionnewlevant/craft-mnbreakandcontinue" rel="nofollow">"Break and Continue"</a>, that gives you a Twig tag for this:</p>
  
  <pre><code>{% for entry in nextEvent %}
  
      {% if entry.startDate &gt; now %}
          {{ entry.startDate }}
          {% break %}
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T14:25:12.720Z
Answers.LastActivityDate: 2015-05-06T14:25:12.720Z
Answers.UserDisplayName: carlcs
Body: <p>I'm trying to find the next event after today (now) from a series of entries. This code however outputs all upcoming events after today but I'm just looking for the first (next) event.</p>
  
  <p>Any help is appreciated</p>
  
  <pre><code>{% set nextEvent =  craft.events.events.find() %}
  {% for entry in nextEvent %}
      {% if entry.startDate &gt; now %}
      &lt;span class="text-primary"&gt;{{ entry.title }}&lt;/span&gt;&lt;br&gt;
      {{ entry.startDate|date('d F Y ') }}
      {% endif %}
  {% endfor %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-06T12:17:58.273Z
Comments.Text: Is this a plugin you're using or is `craft.events.events.find()` a typo in your question?
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-06T12:30:49.863Z
Comments.Text: The find() is a typo. I'm using the Craft events plugin for this.
Comments.UserDisplayName: Robbie Post
Tags: <entries><datetime><events>
Title: Find next event
ThreadText: # Find next event
  
  (Asked by: username_0 on 2015-05-06)
  
  I'm trying to find the next event after today (now) from a series of entries. This code however outputs all upcoming events after today but I'm just looking for the first (next) event.
  
  Any help is appreciated
  
  ```
  {% set nextEvent =  craft.events.events.find() %}
  {% for entry in nextEvent %}
      {% if entry.startDate > now %}
      <span class="text-primary">{{ entry.title }}</span><br>
      {{ entry.startDate|date('d F Y ') }}
      {% endif %}
  {% endfor %}
  
  ```
  
  **Tags:** entries, datetime, events
  
  > **Comments:**
  > **username_1**: Is this a plugin you're using or is `craft.events.events.find()` a typo in your question?  
  > **username_0**: The find() is a typo. I'm using the Craft events plugin for this.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2015-05-06. Score: 3
  
  When you are setting `nextEvent`, you can limit only events that are upcoming and only output the first result you get back like so:
  
  ```
  .startDate('>= ' ~ now).first()
  
  ```
  
  So you can take that and update your code like so:
  
  ```
  {% set nextEvent = craft.entries.section('events').order('startDate').startDate('>= ' ~ now).first() %}
  
  {% if nextEvent %}
      foo
  {% endif %}
  
  ```
  
  I have assumed you have a section called 'Event's until we get some clarification as to what `craft.events.events` is.
  
  > **Comments:**
  > **username_1**: That was fast enough, username_2! Congrats. ;) I'd suggest to use `first` method instead of setting a limit, though.  
  > **username_0**: The code won't work as I'm using the Craft events plugin. {% set nextEvent = craft.entries.events.order('startDate').startDate('>= ' ~ now).limit(1) %} is trowing in an SQL state error (column not found)  
  > **username_2**: @username_0 Hi username_0, please have a look at the answer posted by username_1. The code I supplied will work, but you will need to make some adjustments to how you handle events, as that plugin shouldn't be used in production sites.  
  
  ---
  
  ### Answer by username_1 on 2015-05-06. Score: 2
  
  P&T's events plugin available on GitHub <http://github.com/pixelandtonic/Events> is actually not meant to be used at all. It was just a demo to show the potential of custom element types!
  
  I'd suggest to use a channel section for your events, and with the code username_2 provided you're already done figuring out how to find your "next event"! You could also collect events with a matrix field, if you have a need for an extra level of hierarchy and if that's still not enough you could have your events in a table in that matrix (using the ["Super Table"](https://github.com/engram-design/SuperTable) plugin).
  
  There's also two other plugins: ["Events"](https://github.com/tippingmedia/craft.events) and ["Calendar"](http://michaelrog.com/craft/calendars/introduction), but I'm not sure if they are still under development and I'd probably stick to core Craft features (channels / matrix) for now.
  
  > **Comments:**
  > **username_2**: Thanks for clarifying username_1. I agree, the P&T plugin is a no-go and a channel would be the best option for this.  
  > **username_0**: For me events plugin was a quick and simple solution for a simple project. I solved the issue by hiding the generated list in HTML and only showing the first-child. Thanks for the suggestions  
  > **username_1**: There's a better way to do this, @username_0. I just posted another answer, but please do me a favor and don't accept it. Using P&T plugin is indeed a no-go ...  
  > **username_0**: The breakloop suggestion did the job and solved the issue. It's clear now that the P&T events plugin is not the way to go  
  
  ---
  
  ### Answer by username_1 on 2015-05-06. Score: 2
  
  To break a for loop you could have a variable and check against its value in your loop:
  
  ```
  {% set breakLoop = false %}
  
  {% for entry in nextEvent %}
  
      {% if (entry.startDate > now) and (breakLoop == false) %}
          {{ entry.startDate }}
          {% set breakLoop = true %}
      {% endif %}
  
  {% endfor %}
  
  ```
  
  Or – if you have a need to break loops more often – use the plugin ["Break and Continue"](https://github.com/marionnewlevant/craft-mnbreakandcontinue), that gives you a Twig tag for this:
  
  ```
  {% for entry in nextEvent %}
  
      {% if entry.startDate > now %}
          {{ entry.startDate }}
          {% break %}
      {% endif %}
  
  {% endfor %}
  
  ```
  
  
  ---
  
  