I have some matrix fields defined:

enter image description here

But when I use the matrix blocks inside of an entry - I don't get all blocks - just the richText ones.

I tested it out - just the richtText Matrix blocks will be loaded when I do:

  {% include "_private/partials/matrix" with {blocks: entry.bodyContent.all()} %}

Is there something I am missing, or is this a bug?

Would be great if someone could help.


Without seeing the code of your template _private/partials/matrix it's not easy to help you.

Maybe you need to check the block type first. I usually do that with a switch and have a different partial for each block.

So your template _private/partials/matrix could look something like this:

{% for block in blocks %}
  {% switch block.type %}
    {% case "richText" %}
      {% include "_private/partials/richtext" %}
    {% case "quote" %}
      {% include "_private/partials/qoute" %}
    {% case "image" %}
      {% include "_private/partials/image" %}
    {% case "embed" %}
      {% include "_private/partials/embed" %}
    {% default %}
  {% endswitch %}
{% endfor %}

The quote partial could look something like this

{# do something with block.style #}
  • Thank you for help. The problem is, there are just the Matrix objects with the type of 'richText' the rest ist not even fetched.
    – Slowwie
    Sep 23 '20 at 11:19

I found a solution:

{% include "_private/partials/matrix" with {blocks: entry.bodyContent.typeId(null).all()} %}

This fetches all Matrixobjects from any type. So it works now.

But I don't undestand, why this is necessary. Maybe its because I used for my first project this Blogstarter.

Maybe there are some relicts from craft2 inside.

So I have the solution to my problem - but it would be nice to know why this was necessary.

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.