1

I have a Matrix field setup and working perfectly except for one problem.

In my template I'm using .limit to only pull the first two items from the matrix field (I can't use max in the field settings as I'm using the same field on other pages that allow more than two blocks to show).

Using the following line to pull the Matrix blocks works fine in the live preview.

{% for serviceBlock in entry.serviceBlocks %}

But adding the limit stops Craft showing the blocks in the live preview. Though the rest of the template loads and updates perfectly.

{% for serviceBlock in entry.serviceBlocks.limit(2) %}

I'm not getting any errors, and if I save the page and reload the live preview it will render the blocks perfectly, but not update the content live.

Has anyone encountered this problem, or have an idea that might help?

5

I noticed the same issue with live preview, but using the type property on the Matrix field: Issue with Matrix type property and Live Preview? According to Brandon's answer this is a current bug / limitation of the Matrix field that you have to find a workaround for.

In this case this is rather easy, get all the blocks and use the slice filter to loop over a subset:

{% for serviceBlock in entry.serviceBlocks|slice(0, 2) %}
  • Using slice is a seamless workaround. Thank you for the prompt answer! – Ian Nebbiolo Jun 18 '15 at 15:27

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.