wbrowar / craft-grid

A field that lets you content manage CSS Grid in Craft CMS.
Other
18 stars 2 forks source link

Eager loading matrix blocks #9

Open raptureaid opened 5 years ago

raptureaid commented 5 years ago

I might be missing something, but when trying to eager load matrix blocks I run into the following error: Impossible to access a key ("blockType:assetsField") on a null variable.

Following the documentation from Craft for eager loading and Grid, my template looks like so:

{% grid entry.matrixField.with['blockType:assetsField','blockType2:entriesField'].all() using entry.grid as gridItems %}
  {% for item in gridItems %}
    {% griditem %}
      ...
    {% endgriditem %}
  {% endfor %}
{% endgrid %}

I've intentionally replaced my field labels with generic labels to make it easier to follow along.

If I remove the .with[] statement, the grid loads correctly minus the benefits of eager loading.

wbrowar commented 5 years ago

Hey @raptureaid have you had any luck getting this to work?

My guess is because there's some issue with how matrix block types are getting interpreted here, but since you're doing .all() I believe those should be taken care of before the grid field starts. I can take a look anyway, but I wanted to check in with you first.

raptureaid commented 5 years ago

No, I was able to get a prototype of the pages working on a staging machine, but could not figure out how to get the matrix fields to correctly eager-load (which could totally be user error on my end).