Answers.Body: <p>I could be not following correctly, so I apologize if I'm way off here.</p>
  
  <p>If you want to grab <em>all</em> entries that are selected in your <code>block</code> field, but only want to single out the first one, you could do something like this:</p>
  
  <pre><code>&lt;h2&gt;Program Points&lt;/h2&gt;
  {% for entry in craft.entries.section('program_point') %}
      {% if loop.first %}
          &lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
      {% else %}
          &lt;h3&gt;{{ entry.title }}&lt;/h3&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>The <a href="http://twig.sensiolabs.org/doc/tags/for.html" rel="nofollow">twig for loop</a> has some pretty cool stuff built in that you could leverage to check for the first entry.</p>
  
  <p>Hope this helps!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-06T15:17:57.497Z
Answers.Text: Thanks for the answer!
  But I think this is not what I'm searching for. I only want the entries where the first element in `block` has the title 'first-block'. Maybe now you understand what I mean?
Answers.UserDisplayName: Jonathan Schiffner
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-06T15:27:14.783Z
Answers.Text: Will you be having more than one entry with a title of `first-block`?
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-06T16:20:17.967Z
Answers.Text: yes i will have
Answers.UserDisplayName: Jonathan Schiffner
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-06T15:04:16.723Z
Answers.LastActivityDate: 2016-04-06T15:04:16.723Z
Answers.UserDisplayName: Damon
Body: <p>I want to get the title of the first element from a entries field in a for loop. I think its easier to understand with a code example: </p>
  
  <pre><code>{% set programs = craft.entries.section('program_point').block.first().title('first-block') %}
  {% for program in programs %}
  ...
  {% endfor %}
  </code></pre>
  
  <p><code>block</code> is an entries field. And the loop should only consider entries where the title of the first element in <code>block</code>is <em>first-block</em>.</p>
  
  <p>When I tried this, I always got an error: </p>
  
  <blockquote>
    <p>Impossible to invoke a method ("title") on a null variable</p>
  </blockquote>
  
  <p>But when I did this:</p>
  
  <pre><code>{% set programs = craft.entries.section('program_point') %}
  {% for program in programs %}
          {% if program.block.first().title == 'first-block' %}
               ...
          {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>all worked fine. 
  So how can I check the title of the first element in the for loop?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-06T12:29:55.880Z
Comments.Text: Have you tried to put `.first()` before `.block` ? I think it has something to do with the order of this line.
Comments.UserDisplayName: KSPR
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-06T12:43:16.707Z
Comments.Text: I think this returns the first entry of the section *program_point*. But I need the first element of `block`.
Comments.UserDisplayName: Jonathan Schiffner
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-06T14:59:18.567Z
Comments.Text: Yeah you're right. What about adding `.find()` at the end?
Comments.UserDisplayName: KSPR
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-06T15:14:13.730Z
Comments.Text: Sadly the same result
Comments.UserDisplayName: Jonathan Schiffner
Tags: <templating><forloop><entries-field>
Title: for loop: get the title of the first element of an entries field
ThreadText: # for loop: get the title of the first element of an entries field
  
  (Asked by: username_0 on 2016-04-06)
  
  I want to get the title of the first element from a entries field in a for loop. I think its easier to understand with a code example:
  
  ```
  {% set programs = craft.entries.section('program_point').block.first().title('first-block') %}
  {% for program in programs %}
  ...
  {% endfor %}
  
  ```
  
  `block` is an entries field. And the loop should only consider entries where the title of the first element in `block`is *first-block*.
  
  When I tried this, I always got an error:
  
  > Impossible to invoke a method ("title") on a null variable
  
  But when I did this:
  
  ```
  {% set programs = craft.entries.section('program_point') %}
  {% for program in programs %}
          {% if program.block.first().title == 'first-block' %}
               ...
          {% endif %}
  {% endfor %}
  
  ```
  
  all worked fine.
  So how can I check the title of the first element in the for loop?
  
  **Tags:** templating, forloop, entries-field
  
  > **Comments:**
  > **username_1**: Have you tried to put `.first()` before `.block` ? I think it has something to do with the order of this line.  
  > **username_0**: I think this returns the first entry of the section *program_point*. But I need the first element of `block`.  
  > **username_1**: Yeah you're right. What about adding `.find()` at the end?  
  > **username_0**: Sadly the same result  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-04-06. Score: 1
  
  I could be not following correctly, so I apologize if I'm way off here.
  
  If you want to grab *all* entries that are selected in your `block` field, but only want to single out the first one, you could do something like this:
  
  ```
  <h2>Program Points</h2>
  {% for entry in craft.entries.section('program_point') %}
      {% if loop.first %}
          <h1>{{ entry.title }}</h1>
      {% else %}
          <h3>{{ entry.title }}</h3>
      {% endif %}
  {% endfor %}
  
  ```
  
  The [twig for loop](http://twig.sensiolabs.org/doc/tags/for.html) has some pretty cool stuff built in that you could leverage to check for the first entry.
  
  Hope this helps!
  
  > **Comments:**
  > **username_0**: Thanks for the answer! But I think this is not what I'm searching for. I only want the entries where the first element in `block` has the title 'first-block'. Maybe now you understand what I mean?  
  > **username_2**: Will you be having more than one entry with a title of `first-block`?  
  > **username_0**: yes i will have  
  
  ---
  
  