<p>Since you have 3 block types in your Matrix, you need to check for the block type before trying to call an inner field. </p>

<pre><code>{% block content %}
    &lt;article&gt;
        &lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
        &lt;p&gt;TEST EDIT 8&lt;/p&gt;
        {% for block in entry.blogPost %}
            {% if block.type == 'imageCaption' %}
                &lt;p&gt;heading - {{ block.heading }}&lt;/p&gt;
                &lt;p&gt;sub heading - {{ block.subHeading }}&lt;/p&gt;
            {% elseif block.type == 'WhateverTypeAccoladeIsIn' %}
                &lt;p&gt;accolade- {{ block.accolade }}&lt;/p&gt;
            {% endif %}
        {% endfor %}

        &lt;p&gt;Posted on {{ entry.postDate.format('F d, Y') }}&lt;/p&gt;
        {{ entry.body }}
    &lt;/article&gt;
{% endblock %}
</code></pre>

<p>You should add that check before <code>block.accolade</code> as well for whichever block type accolade is in.</p>

CC BY-SA 3.0
2015-06-24T21:27:59.837Z
2015-06-24T21:27:59.837Z
Aaron Berkowitz
<p>Here's my code block:</p>

<pre><code>{% extends "_layout" %}

{% block content %}
    &lt;article&gt;
        &lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
        &lt;p&gt;TEST EDIT 8&lt;/p&gt;
        {% for block in entry.blogPost %}
            &lt;p&gt;heading - {{ block.heading }}&lt;/p&gt;
            &lt;p&gt;sub heading - {{ block.subHeading }}&lt;/p&gt;
            &lt;p&gt;accolade- {{ block.accolade }}&lt;/p&gt;
        {% endfor %}

        &lt;p&gt;Posted on {{ entry.postDate.format('F d, Y') }}&lt;/p&gt;
        {{ entry.body }}
    &lt;/article&gt;
{% endblock %}
</code></pre>

<p><img src="https://i.sstatic.net/iZ3vj.png" alt="enter image description here"></p>

<p>And here's the error message I am getting on an inconsistent basis:</p>

<blockquote>
  <p>Craft\MatrixBlockModel and its behaviors do not have a method or closure named "heading"</p>
</blockquote>

<p>I've tried to remove the other Matrix fields from the template, and just isolate on the 'block.heading' field, and I get really strange behaviors. Sometimes the template renders fine, and the dynamic value gets rendered by the page. Sometimes, with a different content entry, the same template gives the above error message.</p>

<p>I'm brand new to CraftCMS. Is there an obvious syntax mistake I'm making?</p>

<matrix>
confused by inconsistent behavior of matrix
# confused by inconsistent behavior of matrix

(Asked by: username_0 on 2015-06-24)

Here's my code block:
{% extends "_layout" %}

{% block content %}
    
        {{ entry.title }}
        TEST EDIT 8
        {% for block in entry.blogPost %}
            heading - {{ block.heading }}
            sub heading - {{ block.subHeading }}
            accolade- {{ block.accolade }}
        {% endfor %}

        Posted on {{ entry.postDate.format('F d, Y') }}
        {{ entry.body }}
    
{% endblock %}


And here's the error message I am getting on an inconsistent basis:

Craft\MatrixBlockModel and its behaviors do not have a method or closure named "heading"

I've tried to remove the other Matrix fields from the template, and just isolate on the 'block.heading' field, and I get really strange behaviors. Sometimes the template renders fine, and the dynamic value gets rendered by the page. Sometimes, with a different content entry, the same template gives the above error message.
I'm brand new to CraftCMS. Is there an obvious syntax mistake I'm making?

**Tags:** matrix

---

## 1 answers

### Answer by username_1 on 2015-06-24. Score: 5 | Accepted answer

Since you have 3 block types in your Matrix, you need to check for the block type before trying to call an inner field. 
{% block content %}
    
        {{ entry.title }}
        TEST EDIT 8
        {% for block in entry.blogPost %}
            {% if block.type == 'imageCaption' %}
                heading - {{ block.heading }}
                sub heading - {{ block.subHeading }}
            {% elseif block.type == 'WhateverTypeAccoladeIsIn' %}
                accolade- {{ block.accolade }}
            {% endif %}
        {% endfor %}

        Posted on {{ entry.postDate.format('F d, Y') }}
        {{ entry.body }}
    
{% endblock %}

You should add that check before block.accolade as well for whichever block type accolade is in.


---

