isNotEmpty() not working on blocks field

I’ve got an issue, first the code block:

<?php if ($card->story()->isNotEmpty()): ?>
<p><a href="<?= $card->url() ?>">Continue</i></a></p>
<?php endif ?>

story() is a blocks field, defined as this in blueprint:

story:
  label: Post
  type: blocks

Now, in the initial state when I don’t add a text to “story”, the snippet above works as intended. “Continue” isn’t shown.

But now when I add some text to “story” and delete it again, it stops working. Now I looked directly in text file to see what’s stored to story file when everything is deleted and I see this:

----
Story: []
----

When I manualy remove the brackets, snippet works again. Is there a way to stop CMS from creating brackets when the content of story is being deleted from panel or is there a workaround snippet for solving this situation=

If you check for a block collection instead of checking if the field is empty, it should work.

<?php if ($card->story()->toBlocks()->isNotEmpty()): ?>
1 Like

Thanks for saving my day second time today :slight_smile:

This issue fixed on 3.5.7 that still RC and will be release next Tuesday. You can check the blocks empty without converting via ->toBlocks(). So $card->story()->isNotEmpty()will work on 3.5.7.

1 Like