Crop() doesn't work in if-condition (empty object)

Hi everyone,

in a template I use the e() function to check if there is a cover-image set in the panel. If yes, I want to display and crop() it. Everything works as long as the if-condition is true. But if it’s false, the page breaks. I think it’s because I want to crop an image that isn’t there.

The code looks like this:

e($page->cover()->isNotEmpty(), $page->image($page->cover())->crop(300));

If it’s not correct to use e() like that, what would the alternative be, checking for a cover-image and showing it cropped?

Thank you,
D

You can’t use e/ecco in this context, either use a proper if statement or the ternary operator.

<?php echo $page->cover()->isNotEmpty()? $page->image($page->cover())->crop(300): '' ?>

Ok, thank you! :slight_smile: