for loop: get the title of the first element of an entries field 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 blockis 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?
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:

&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 %}


The twig for loop has some pretty cool stuff built in that you could leverage to check for the first entry.

Hope this helps!