1

Here's my code block:

{% extends "_layout" %}

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

        <p>Posted on {{ entry.postDate.format('F d, Y') }}</p>
        {{ entry.body }}
    </article>
{% endblock %}

enter image description here

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?

5

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 %}
    <article>
        <h1>{{ entry.title }}</h1>
        <p>TEST EDIT 8</p>
        {% for block in entry.blogPost %}
            {% if block.type == 'imageCaption' %}
                <p>heading - {{ block.heading }}</p>
                <p>sub heading - {{ block.subHeading }}</p>
            {% elseif block.type == 'WhateverTypeAccoladeIsIn' %}
                <p>accolade- {{ block.accolade }}</p>
            {% endif %}
        {% endfor %}

        <p>Posted on {{ entry.postDate.format('F d, Y') }}</p>
        {{ entry.body }}
    </article>
{% endblock %}

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.